// File: sunweilun[P]Delaunay/Mesh.cpp
// Function: Mesh::insertVertex(unsigned int)
void Mesh::insertVertex(unsigned vIndex)
{
    std::unordered_set<llu> checked; // set of checked edges (Hash Values)
    std::stack<unsigned> suspEdgeIndices; // stack of suspicious edges
    HalfEdge e;

    unsigned oldEdgeIndices[3];

    unsigned eIndexList[3][2];

    unsigned oldTriIndex = locateTriangle(vIndex);

    for(int i=0; i<3; i++)
    {
        unsigned eIndex = triangles[oldTriIndex].eIndices[i];
        HalfEdge &oldEdge = halfEdges[eIndex];
        suspEdgeIndices.push(eIndex); // Edges of the old triangle are suspicious.

        oldEdgeIndices[i] = eIndex;

        // new edge
        e.vIndices[0] = oldEdge.vIndices[1];
        e.vIndices[1] = vIndex;
        halfEdges.push_back(e);
        eIndexList[i][0] = unsigned(halfEdges.size())-1;

        // new edge
        e.vIndices[1] = oldEdge.vIndices[1];
        e.vIndices[0] = vIndex;
        halfEdges.push_back(e);
        eIndexList[i][1] = unsigned(halfEdges.size())-1;
    }

    for(int i=0; i<3; i++)
    {
        unsigned eIndex = oldEdgeIndices[i];
        int prev_i = (i+2)%3;

        unsigned tIndex = unsigned(triangles.size());
        if(i > 0)
            triangles.push_back(Triangle());
        else
            tIndex = oldTriIndex;

        fillTriangle(tIndex, eIndex, eIndexList[i][0], eIndexList[prev_i][1]);
        pairEdges(eIndexList[i][0], eIndexList[i][1]);
        checked.insert(halfEdges[eIndexList[i][0]].getHashValue());
        checked.insert(halfEdges[eIndexList[i][1]].getHashValue());
    }

    correctEdges(suspEdgeIndices, checked);

    if(method == CONFLICT_GRAPH) // redistribute
    {
        updateConfGraph(vIndex, oldTriIndex);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x188(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x5d20
leaq -0x98(%rbp), %rdi
callq 0x5d40
jmp 0x34a4
leaq -0xbc(%rbp), %rdi
callq 0x4870
jmp 0x34b2
movq -0x188(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x27d0
movl %eax, -0x18c(%rbp)
jmp 0x34c9
movl -0x18c(%rbp), %eax
movl %eax, -0xe4(%rbp)
movl $0x0, -0xe8(%rbp)
cmpl $0x3, -0xe8(%rbp)
jge 0x364a
movq -0x188(%rbp), %rdi
addq $0x28, %rdi
movl -0xe4(%rbp), %eax
movl %eax, %esi
callq 0x4b60
movq -0x188(%rbp), %rdi
movslq -0xe8(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0xec(%rbp)
addq $0x40, %rdi
movl -0xec(%rbp), %eax
movl %eax, %esi
callq 0x4990
movq %rax, -0xf8(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xec(%rbp), %rsi
callq 0x5af0
jmp 0x3548
movq -0x188(%rbp), %rdi
movl -0xec(%rbp), %ecx
movslq -0xe8(%rbp), %rax
movl %ecx, -0xc8(%rbp,%rax,4)
movq -0xf8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xbc(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0xb8(%rbp)
addq $0x40, %rdi
leaq -0xbc(%rbp), %rsi
callq 0x4920
jmp 0x358e
movq -0x188(%rbp), %rdi
addq $0x40, %rdi
movq %rdi, -0x198(%rbp)
callq 0x4b30
movq -0x198(%rbp), %rdi
movl %eax, %ecx
decl %ecx
movslq -0xe8(%rbp), %rax
movl %ecx, -0xe0(%rbp,%rax,8)
movq -0xf8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xb8(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0xbc(%rbp)
leaq -0xbc(%rbp), %rsi
callq 0x4920
jmp 0x35e5
movq -0x188(%rbp), %rdi
addq $0x40, %rdi
callq 0x4b30
movl %eax, %ecx
subl $0x1, %ecx
movslq -0xe8(%rbp), %rax
movl %ecx, -0xdc(%rbp,%rax,8)
movl -0xe8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe8(%rbp)
jmp 0x34df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x38e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x38d4
movl $0x0, -0xfc(%rbp)
cmpl $0x3, -0xfc(%rbp)
jge 0x3877
movq -0x188(%rbp), %rdi
movslq -0xfc(%rbp), %rax
movl -0xc8(%rbp,%rax,4), %eax
movl %eax, -0x100(%rbp)
movl -0xfc(%rbp), %eax
addl $0x2, %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %edx, -0x104(%rbp)
addq $0x28, %rdi
callq 0x4a40
movl %eax, -0x108(%rbp)
cmpl $0x0, -0xfc(%rbp)
jle 0x3711
movq -0x188(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x1a0(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x4830
jmp 0x36cb
movq -0x1a0(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x5d70
jmp 0x36e0
leaq -0x150(%rbp), %rdi
callq 0x4a20
jmp 0x371d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x4a20
jmp 0x38d4
movl -0xe4(%rbp), %eax
movl %eax, -0x108(%rbp)
movq -0x188(%rbp), %rdi
movl -0x108(%rbp), %esi
movl -0x100(%rbp), %edx
movslq -0xfc(%rbp), %rax
movl -0xe0(%rbp,%rax,8), %ecx
movslq -0x104(%rbp), %rax
movl -0xdc(%rbp,%rax,8), %r8d
callq 0x28e0
movq -0x188(%rbp), %rdi
movslq -0xfc(%rbp), %rax
movl -0xe0(%rbp,%rax,8), %esi
movl -0xdc(%rbp,%rax,8), %edx
callq 0x2880
movq -0x188(%rbp), %rdi
addq $0x40, %rdi
movslq -0xfc(%rbp), %rax
movl -0xe0(%rbp,%rax,8), %eax
movl %eax, %esi
callq 0x4990
movq %rax, %rdi
callq 0x5a60
movq %rax, -0x1a8(%rbp)
jmp 0x37a4
movq -0x1a8(%rbp), %rax
movq %rax, -0x158(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x5ab0
movb %dl, -0x1b1(%rbp)
movq %rax, -0x1b0(%rbp)
jmp 0x37d1
movq -0x188(%rbp), %rdi
movb -0x1b1(%rbp), %al
movq -0x1b0(%rbp), %rcx
movq %rcx, -0x168(%rbp)
movb %al, -0x160(%rbp)
addq $0x40, %rdi
movslq -0xfc(%rbp), %rax
movl -0xdc(%rbp,%rax,8), %eax
movl %eax, %esi
callq 0x4990
movq %rax, %rdi
callq 0x5a60
movq %rax, -0x1c0(%rbp)
jmp 0x381c
movq -0x1c0(%rbp), %rax
movq %rax, -0x170(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x5ab0
movb %dl, -0x1c9(%rbp)
movq %rax, -0x1c8(%rbp)
jmp 0x3849
movb -0x1c9(%rbp), %al
movq -0x1c8(%rbp), %rcx
movq %rcx, -0x180(%rbp)
movb %al, -0x178(%rbp)
movl -0xfc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xfc(%rbp)
jmp 0x3654
movq -0x188(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0x2d00
jmp 0x3890
movq -0x188(%rbp), %rax
cmpl $0x1, 0x8(%rax)
jne 0x38b6
movq -0x188(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0xe4(%rbp), %edx
callq 0x30e0
jmp 0x38b4
jmp 0x38b6
leaq -0x98(%rbp), %rdi
callq 0x5da0
leaq -0x48(%rbp), %rdi
callq 0x5dc0
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
leaq -0x98(%rbp), %rdi
callq 0x5da0
leaq -0x48(%rbp), %rdi
callq 0x5dc0
movq -0xa0(%rbp), %rdi
callq 0x11c0
nopw %cs:(%rax,%rax)