// File: 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
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x59a0
cmpq $0x0, %rax
je 0x2f7e
movq -0x10(%rbp), %rdi
callq 0x59c0
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x59e0
movq -0xa8(%rbp), %rdi
addq $0x40, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x4990
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x28(%rbp), %rdi
callq 0x5a60
movq -0xb0(%rbp), %rdi
movq %rax, -0x38(%rbp)
leaq -0x38(%rbp), %rsi
callq 0x5a30
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
callq 0x5a80
movq %rax, -0x40(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x5a00
testb $0x1, %al
jne 0x2db1
jmp 0x2db6
jmp 0x2d22
movq -0x18(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x28(%rbp), %rdi
callq 0x5a60
movq -0xb8(%rbp), %rdi
movq %rax, -0x48(%rbp)
leaq -0x48(%rbp), %rsi
callq 0x5ab0
movq %rax, -0x58(%rbp)
movb %dl, -0x50(%rbp)
movq -0x28(%rbp), %rax
cmpl $-0x1, 0x14(%rax)
jne 0x2df4
jmp 0x2d22
movq -0xa8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq %rax, -0xc0(%rbp)
addq $0x40, %rdi
movq -0x28(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, %esi
callq 0x4990
movq %rax, %rdi
callq 0x5a60
movq -0xc0(%rbp), %rdi
movq %rax, -0x60(%rbp)
leaq -0x60(%rbp), %rsi
callq 0x5ab0
movq -0xa8(%rbp), %rdi
movq %rax, -0x70(%rbp)
movb %dl, -0x68(%rbp)
movl -0x1c(%rbp), %esi
callq 0x29c0
testb $0x1, %al
jne 0x2e50
jmp 0x2e55
jmp 0x2d22
movq -0xa8(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x2f90
movq -0x18(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x28(%rbp), %rdi
callq 0x5a60
movq -0xe0(%rbp), %rdi
movq %rax, -0x78(%rbp)
leaq -0x78(%rbp), %rsi
callq 0x5ab0
movq -0xa8(%rbp), %rdi
movq %rax, -0x88(%rbp)
movb %dl, -0x80(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xd8(%rbp)
addq $0x40, %rdi
movq -0x28(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, %esi
callq 0x4990
movq %rax, %rdi
callq 0x5a60
movq -0xd8(%rbp), %rdi
movq %rax, -0x90(%rbp)
leaq -0x90(%rbp), %rsi
callq 0x5ab0
movq %rax, -0xa0(%rbp)
movb %dl, -0x98(%rbp)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0xc, %rsi
callq 0x5af0
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x10, %rsi
callq 0x5af0
movq -0xa8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq %rax, -0xd0(%rbp)
addq $0x40, %rdi
movq -0x28(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, %esi
callq 0x4990
movq -0xd0(%rbp), %rdi
movq %rax, %rsi
addq $0xc, %rsi
callq 0x5af0
movq -0xa8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq %rax, -0xc8(%rbp)
addq $0x40, %rdi
movq -0x28(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, %esi
callq 0x4990
movq -0xc8(%rbp), %rdi
movq %rax, %rsi
addq $0x10, %rsi
callq 0x5af0
jmp 0x2d22
addq $0xe0, %rsp
popq %rbp
retq
nopw (%rax,%rax)