// File: /workspace/github_cpp_makefile_star2_O1/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 $0x28, %rsp
movl %r9d, %r12d
movl %r8d, %r13d
movl %ecx, %ebx
movl %edx, %ebp
movq %rdi, %r14
movl 0x60(%rsp), %r15d
movl %esi, 0x24(%rsp)
testl %esi, %esi
je 0x40357f
leal 0x1(%r15), %edx
movq %r14, %rdi
movl %r15d, %esi
movl %edx, %r15d
movl %r12d, %ecx
movl %ebx, %r8d
callq 0x40266a
addl $0x3, %ebx
testl %ebp, %ebp
je 0x4036e1
cmpl $0x1, %ebp
je 0x40365c
cmpl $0x2, %ebp
jne 0x4037b0
xorl %ebp, %ebp
cmpl $0x2, %r13d
jl 0x40360b
movl %r13d, %eax
shrl $0x1f, %eax
movq %r13, 0x18(%rsp)
addl %r13d, %eax
sarl %eax
movq %r14, 0x10(%rsp)
movl %eax, 0x8(%rsp)
movl %eax, %r14d
movq 0x10(%rsp), %r13
movl %r12d, %ecx
movl %r15d, %ebp
leal 0x1(%rcx), %r12d
movq %r13, %rdi
movl %r15d, %esi
movl %r12d, %edx
movl %ebx, %r8d
callq 0x40266a
leal 0x1(%rbp), %r15d
leal 0x3(%rbx), %r8d
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %edx
movl %r12d, %ecx
callq 0x40266a
addl $0x6, %ebx
decl %r14d
jne 0x4035c2
movq 0x10(%rsp), %r14
movl 0x8(%rsp), %ebp
movq 0x18(%rsp), %r13
leal -0x1(%r13), %eax
cmpl %eax, %ebp
jge 0x4037b0
notl %ebp
addl %r13d, %ebp
movl %r12d, %r13d
movl %r15d, %edx
leal 0x1(%rdx), %r15d
movq %r14, %rdi
movl %r12d, %esi
movl %r15d, %ecx
movl %ebx, %r8d
callq 0x40266a
leal 0x1(%r13), %r12d
leal 0x3(%rbx), %r8d
movq %r14, %rdi
movl %r13d, %esi
movl %r15d, %edx
movl %r12d, %ecx
callq 0x40266a
addl $0x6, %ebx
decl %ebp
jne 0x40361c
jmp 0x4037b0
cmpl $0x4, %r13d
jl 0x40372e
movq %r13, 0x18(%rsp)
movl %r13d, %eax
shrl %eax
cmpl $0x3, %eax
movl $0x2, %ecx
cmovgel %eax, %ecx
movq %r14, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
leal -0x1(%rcx), %r14d
movq 0x10(%rsp), %r13
movl %r12d, %ebp
movl %r15d, %esi
leal 0x1(%rsi), %r15d
movq %r13, %rdi
movl %r15d, %edx
movl %r12d, %ecx
movl %ebx, %r8d
callq 0x40266a
leal 0x1(%rbp), %r12d
leal 0x3(%rbx), %r8d
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %edx
movl %r12d, %ecx
callq 0x40266a
addl $0x6, %ebx
decl %r14d
jne 0x40368e
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r13
jmp 0x403738
cmpl $0x2, %r13d
jl 0x4037b0
decl %r13d
movl %r12d, %ebp
movl %r15d, %edx
leal 0x1(%rdx), %r15d
movq %r14, %rdi
movl %r12d, %esi
movl %r15d, %ecx
movl %ebx, %r8d
callq 0x40266a
leal 0x1(%rbp), %r12d
leal 0x3(%rbx), %r8d
movq %r14, %rdi
movl %ebp, %esi
movl %r15d, %edx
movl %r12d, %ecx
callq 0x40266a
addl $0x6, %ebx
decl %r13d
jne 0x4036ee
jmp 0x4037b0
movl $0x2, %eax
movq %rax, 0x8(%rsp)
movl %r15d, %ebp
movl %r12d, %ecx
leal 0x1(%rcx), %r12d
movq %r14, %rdi
movl %r15d, %esi
movl %r12d, %edx
movl %ebx, %r8d
callq 0x40266a
leal 0x3(%rbx), %r8d
leal 0x1(%rbp), %r15d
movq %r14, %rdi
movl %ebp, %esi
movl %r15d, %edx
movl %r12d, %ecx
callq 0x40266a
addl $0x6, %ebx
subl 0x8(%rsp), %r13d
jle 0x4037b0
movl %r12d, %ebp
movl %r15d, %esi
leal 0x1(%rsi), %r15d
movq %r14, %rdi
movl %r15d, %edx
movl %r12d, %ecx
movl %ebx, %r8d
callq 0x40266a
leal 0x1(%rbp), %r12d
leal 0x3(%rbx), %r8d
movq %r14, %rdi
movl %ebp, %esi
movl %r15d, %edx
movl %r12d, %ecx
callq 0x40266a
addl $0x6, %ebx
decl %r13d
jne 0x403775
cmpb $0x0, 0x24(%rsp)
je 0x4037da
leal 0x1(%r15), %edx
movq %r14, %rdi
movl %r15d, %esi
movl %r12d, %ecx
movl %ebx, %r8d
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x40266a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop