// File: /workspace/github_cpp_makefile_star2_O2/sunweilun[P]Delaunay/Mesh.cpp
// Function: Mesh::buildGhostTriangle(std::vector<glm::detail::tvec3<double, (glm::precision)0>, std::allocator<glm::detail::tvec3<double, (glm::precision)0>>> const&)
void Mesh::buildGhostTriangle(const std::vector<vec3>& vList)
{
    vec3 vPos[3];
    vec3 centroid(0, 0, 0);
    real radius = 0;
    for(auto it = vList.begin(); it != vList.end(); it++)
    {
        centroid += *it;
    }
    centroid /= real(vList.size());
    centroid.z = 1;

    for(auto it = vList.begin(); it != vList.end(); it++)
    {
        real dist = glm::length(*it - centroid);
        if(dist > radius)
            radius = dist;
    }

    centroid.z = 0;

    vPos[0] = centroid + vec3(-radius*2, -radius, 0);
    vPos[1] = centroid + vec3(radius*2, -radius, 0);
    vPos[2] = centroid + vec3(0, radius*2, 0);

    Vertex v;
    Triangle t;
    HalfEdge e;

    v.pos = vPos[0];
    vertices.push_back(v);

    v.pos = vPos[1];
    vertices.push_back(v);

    v.pos = vPos[2];
    vertices.push_back(v);

    halfEdges.push_back(e);
    halfEdges.push_back(e);
    halfEdges.push_back(e);

    for(int i=0; i<3; i++)
    {
        int j = (i+1)%3;
        halfEdges[i].vIndices[0] = i;
        halfEdges[i].vIndices[1] = j;
        halfEdges[i].nextIndex = j;
        halfEdges[j].prevIndex = i;
        t.eIndices[i] = i;
    }
    triangles.push_back(t);
    for(int i=0; i<3; i++)
    {
        halfEdges[i].tIndex = 0;
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0xc0, %rsp
movq %rdi, %rbx
movq (%rsi), %rcx
movq 0x8(%rsi), %rsi
xorpd %xmm6, %xmm6
movq %rcx, %rax
cmpq %rsi, %rax
je 0x1426
movupd (%rax), %xmm0
addpd %xmm0, %xmm6
addq $0x18, %rax
jmp 0x1413
movq %rsi, %rax
subq %rcx, %rax
pushq $0x18
popq %rdi
cqto
idivq %rdi
movq %rax, %xmm0
punpckldq 0x4bcf(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x4bd7(%rip), %xmm0     # 0x6020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
addpd %xmm1, %xmm0
divpd %xmm0, %xmm6
movapd %xmm6, %xmm1
unpckhpd %xmm6, %xmm1            # xmm1 = xmm1[1],xmm6[1]
xorpd %xmm0, %xmm0
movsd 0x4bdf(%rip), %xmm2     # 0x6050
cmpq %rsi, %rcx
je 0x14b6
movsd (%rcx), %xmm3
movsd 0x8(%rcx), %xmm4
subsd %xmm6, %xmm3
subsd %xmm1, %xmm4
movsd 0x10(%rcx), %xmm5
addsd %xmm2, %xmm5
mulsd %xmm4, %xmm4
mulsd %xmm3, %xmm3
addsd %xmm4, %xmm3
mulsd %xmm5, %xmm5
addsd %xmm3, %xmm5
sqrtsd %xmm5, %xmm3
maxsd %xmm0, %xmm3
addq $0x18, %rcx
movapd %xmm3, %xmm0
jmp 0x1471
movapd %xmm0, %xmm2
xorpd %xmm1, %xmm1
leaq 0xb8(%rsp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
movupd %xmm1, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movupd %xmm1, -0x8(%rax)
orl $-0x1, -0x38(%rax)
addsd %xmm0, %xmm2
orq $-0x1, -0x40(%rax)
leaq 0x88(%rsp), %r14
orq $-0x1, 0x10(%rsp)
pcmpeqd %xmm1, %xmm1
movdqa %xmm1, (%rsp)
movapd %xmm2, 0x30(%rsp)
movapd %xmm2, %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movapd %xmm6, %xmm0
subpd %xmm1, %xmm0
leaq 0x58(%rsp), %rsi
movapd %xmm0, 0x40(%rsp)
movupd %xmm0, 0x8(%rsi)
andq $0x0, 0x18(%rsi)
leaq 0x10(%rbx), %r15
movq %r15, %rdi
movapd %xmm6, 0x20(%rsp)
callq 0x2a8a
movapd 0x20(%rsp), %xmm0
addsd 0x30(%rsp), %xmm0
leaq 0x58(%rsp), %rsi
movsd %xmm0, 0x8(%rsi)
movapd 0x40(%rsp), %xmm0
movhpd %xmm0, 0x10(%rsi)
andq $0x0, 0x18(%rsi)
movq %r15, %rdi
callq 0x2a8a
xorpd %xmm0, %xmm0
unpcklpd 0x30(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0]
movapd 0x20(%rsp), %xmm1
addpd %xmm0, %xmm1
leaq 0x58(%rsp), %rsi
movupd %xmm1, 0x8(%rsi)
andq $0x0, 0x18(%rsi)
movq %r15, %rdi
callq 0x2a8a
leaq 0x40(%rbx), %r15
movq %rsp, %rsi
movq %r15, %rdi
callq 0x2ac4
movq %rsp, %rsi
movq %r15, %rdi
callq 0x2ac4
movq %rsp, %rsi
movq %r15, %rdi
callq 0x2ac4
movq (%r15), %rax
xorl %ecx, %ecx
movq %rax, %rdx
xorl %esi, %esi
cmpq $0x3, %rsi
je 0x1607
leaq 0x1(%rsi), %rdi
cmpq $0x3, %rdi
movl %edi, %r8d
cmovel %ecx, %r8d
leal -0x1(%rdi), %r9d
movl %r9d, (%rdx)
movl %r8d, 0x4(%rdx)
movl %r8d, 0xc(%rdx)
imulq $0x18, %r8, %r8
movl %r9d, 0x10(%rax,%r8)
movl %r9d, 0x78(%rsp,%rsi,4)
addq $0x18, %rdx
movq %rdi, %rsi
jmp 0x15cc
addq $0x28, %rbx
leaq 0x78(%rsp), %rsi
movq %rbx, %rdi
callq 0x2aea
movq (%r15), %rax
pushq $0x8
popq %rcx
cmpq $0x50, %rcx
je 0x162e
andl $0x0, (%rax,%rcx)
addq $0x18, %rcx
jmp 0x161e
movq %r14, %rdi
callq 0x3018
addq $0xc0, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
movq %r14, %rdi
callq 0x3018
movq %rbx, %rdi
callq 0x11a0