// File: /workspace/github_cpp_makefile_star2_O3/sunweilun[P]Delaunay/Mesh.cpp
// Function: Mesh::correctEdges(std::stack<unsigned int, std::deque<unsigned int, std::allocator<unsigned int>>>&, std::unordered_set<unsigned long long, std::hash<unsigned long long>, std::equal_to<unsigned long long>, std::allocator<unsigned long long>>&)
void Mesh::correctEdges(std::stack<unsigned>& suspEdgeIndices, std::unordered_set<llu>& checked)
{
    while(suspEdgeIndices.size())
    {
        unsigned eIndex = suspEdgeIndices.top();
        suspEdgeIndices.pop();
        const HalfEdge &e = halfEdges[eIndex];
        if(checked.find(e.getHashValue()) != checked.end()) // Skip edges that have already been checked.
            continue;
        checked.insert(e.getHashValue());
        if(e.neighborIndex == MAX_UINT) // No neighbor, must be Delaunay.
            continue;
        checked.insert(halfEdges[e.neighborIndex].getHashValue());
        if(isDelaunay(eIndex))
            continue;
        flipEdge(eIndex);
        checked.insert(e.getHashValue());
        checked.insert(halfEdges[e.neighborIndex].getHashValue());
        suspEdgeIndices.push(e.nextIndex);
        suspEdgeIndices.push(e.prevIndex);
        suspEdgeIndices.push(halfEdges[e.neighborIndex].nextIndex);
        suspEdgeIndices.push(halfEdges[e.neighborIndex].prevIndex);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, 0x10(%rsp)
movq 0x48(%r14), %rax
movq %rax, %rsi
subq 0x28(%r14), %rsi
shrq $0x3, %rsi
cmpq $0x1, %rax
adcq $-0x1, %rsi
shlq $0x7, %rsi
movq 0x20(%r14), %rdi
movq 0x30(%r14), %rcx
movq 0x38(%r14), %rdx
movq %rcx, %r8
subq %rdx, %r8
sarq $0x2, %r8
addq %rsi, %r8
subq 0x10(%r14), %rdi
sarq $0x2, %rdi
addq %r8, %rdi
je 0x2708
movq %rbx, %r15
cmpq %rdx, %rcx
jne 0x24e8
movq -0x8(%rax), %rcx
movl $0x200, %eax            # imm = 0x200
addq %rax, %rcx
movl -0x4(%rcx), %ebp
movq %r14, %rdi
callq 0x4bd0
movq 0x10(%rsp), %rax
movq 0x40(%rax), %r13
leaq (,%rbp,2), %r12
addq %rbp, %r12
movl (%r13,%r12,8), %eax
movl 0x4(%r13,%r12,8), %ecx
shlq $0x20, %rax
orq %rax, %rcx
movq %rcx, (%rsp)
movq %r15, %rbx
movq %r15, %rdi
movq %rsp, %rsi
callq 0x4c1c
testq %rax, %rax
jne 0x248f
leaq (%r13,%r12,8), %r13
movl (%r13), %eax
movl 0x4(%r13), %ecx
shlq $0x20, %rax
orq %rax, %rcx
movq %rcx, 0x8(%rsp)
movq %rbx, (%rsp)
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
movq %rsp, %rdx
callq 0x4c78
movl 0x14(%r13), %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
je 0x248f
movq 0x10(%rsp), %r12
movq 0x40(%r12), %rcx
leaq (%rax,%rax,2), %rax
movl (%rcx,%rax,8), %edx
movl 0x4(%rcx,%rax,8), %eax
shlq $0x20, %rdx
orq %rdx, %rax
movq %rax, 0x8(%rsp)
movq %rbx, (%rsp)
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
movq %rsp, %rdx
callq 0x4c78
movq %r12, %rdi
movl %ebp, %esi
callq 0x20d2
testb %al, %al
jne 0x248f
movq 0x10(%rsp), %rdi
movl %ebp, %esi
callq 0x2718
movl (%r13), %eax
movl 0x4(%r13), %ecx
shlq $0x20, %rax
orq %rax, %rcx
movq %rcx, 0x8(%rsp)
movq %rbx, (%rsp)
movq %rbx, %rdi
leaq 0x8(%rsp), %rbp
movq %rbp, %rsi
movq %rsp, %r12
movq %r12, %rdx
callq 0x4c78
movl 0x14(%r13), %eax
movq 0x10(%rsp), %rcx
movq 0x40(%rcx), %rcx
leaq (%rax,%rax,2), %rax
movl (%rcx,%rax,8), %edx
movl 0x4(%rcx,%rax,8), %eax
shlq $0x20, %rdx
orq %rdx, %rax
movq %rax, 0x8(%rsp)
movq %rbx, (%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x4c78
leaq 0xc(%r13), %rsi
movq 0x30(%r14), %rax
movq 0x40(%r14), %rcx
leaq -0x4(%rcx), %rdx
cmpq %rdx, %rax
je 0x264c
movl (%rsi), %edx
movl %edx, (%rax)
addq $0x4, %rax
movq %rax, 0x30(%r14)
jmp 0x265c
movq %r14, %rdi
callq 0x4f06
movq 0x30(%r14), %rax
movq 0x40(%r14), %rcx
leaq 0x10(%r13), %rsi
leaq -0x4(%rcx), %rdx
cmpq %rdx, %rax
movq 0x10(%rsp), %rbx
je 0x267c
movl (%rsi), %edx
movl %edx, (%rax)
addq $0x4, %rax
movq %rax, 0x30(%r14)
jmp 0x268c
movq %r14, %rdi
callq 0x4f06
movq 0x30(%r14), %rax
movq 0x40(%r14), %rcx
movl 0x14(%r13), %esi
movq 0x40(%rbx), %rdx
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rsi
addq $0xc, %rsi
leaq -0x4(%rcx), %rdi
cmpq %rdi, %rax
je 0x26b7
movl (%rsi), %esi
movl %esi, (%rax)
addq $0x4, %rax
movq %rax, 0x30(%r14)
jmp 0x26cb
movq %r14, %rdi
callq 0x4f06
movq 0x40(%rbx), %rdx
movq 0x30(%r14), %rax
movq 0x40(%r14), %rcx
movl 0x14(%r13), %esi
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rsi
addq $0x10, %rsi
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x26f8
movl (%rsi), %ecx
movl %ecx, (%rax)
addq $0x4, %rax
movq %rax, 0x30(%r14)
movq %r15, %rbx
jmp 0x248f
movq %r14, %rdi
callq 0x4f06
movq %r15, %rbx
jmp 0x248f
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop