// File: /workspace/github_cpp_makefile_star2_O3/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), %rax
cmpq %rax, %rcx
je 0x163f
xorpd %xmm6, %xmm6
movq %rcx, %rdx
movupd (%rdx), %xmm0
addpd %xmm0, %xmm6
addq $0x18, %rdx
cmpq %rax, %rdx
jne 0x1588
movq %rax, %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rsi
movq %rsi, %xmm0
punpckldq 0x4a52(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x4a5a(%rip), %xmm0     # 0x6020
movapd %xmm0, %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addpd %xmm1, %xmm0
divpd %xmm0, %xmm6
cmpq %rcx, %rax
je 0x1687
movapd %xmm6, %xmm1
unpckhpd %xmm6, %xmm1            # xmm1 = xmm1[1],xmm6[1]
xorpd %xmm0, %xmm0
movsd 0x4a59(%rip), %xmm2     # 0x6050
movapd %xmm0, %xmm3
movsd (%rcx), %xmm0
movsd 0x8(%rcx), %xmm4
subsd %xmm6, %xmm0
subsd %xmm1, %xmm4
movsd 0x10(%rcx), %xmm5
addsd %xmm2, %xmm5
mulsd %xmm4, %xmm4
mulsd %xmm0, %xmm0
addsd %xmm4, %xmm0
mulsd %xmm5, %xmm5
addsd %xmm0, %xmm5
xorps %xmm0, %xmm0
sqrtsd %xmm5, %xmm0
maxsd %xmm3, %xmm0
addq $0x18, %rcx
cmpq %rax, %rcx
jne 0x15f7
jmp 0x168b
subq %rcx, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rcx
movq %rcx, %xmm0
punpckldq 0x49af(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x49b7(%rip), %xmm0     # 0x6020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
xorpd %xmm6, %xmm6
divsd %xmm1, %xmm6
unpcklpd %xmm6, %xmm6            # xmm6 = xmm6[0,0]
jmp 0x168b
xorpd %xmm0, %xmm0
movapd %xmm6, 0x20(%rsp)
movapd %xmm0, %xmm2
addsd %xmm0, %xmm2
xorpd %xmm1, %xmm1
leaq 0x88(%rsp), %r14
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)
movl $0xffffffff, -0x38(%rax) # imm = 0xFFFFFFFF
movq $-0x1, %rcx
movq %rcx, -0x40(%rax)
movq %rcx, 0x10(%rsp)
pcmpeqd %xmm1, %xmm1
movdqa %xmm1, (%rsp)
movapd %xmm2, 0x30(%rsp)
movapd %xmm2, %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
subpd %xmm1, %xmm6
leaq 0x58(%rsp), %rsi
movapd %xmm6, 0x40(%rsp)
movupd %xmm6, 0x8(%rsi)
movq $0x0, 0x18(%rsi)
leaq 0x10(%rbx), %r15
movq %r15, %rdi
callq 0x33b2
movapd 0x20(%rsp), %xmm0
addsd 0x30(%rsp), %xmm0
leaq 0x58(%rsp), %rsi
movsd %xmm0, 0x8(%rsi)
movapd 0x40(%rsp), %xmm0
movhpd %xmm0, 0x10(%rsi)
movq $0x0, 0x18(%rsi)
movq %r15, %rdi
callq 0x33b2
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)
movq $0x0, 0x18(%rsi)
movq %r15, %rdi
callq 0x33b2
leaq 0x40(%rbx), %r15
movq 0x48(%rbx), %rsi
cmpq 0x50(%rbx), %rsi
je 0x17ad
movq 0x10(%rsp), %rax
movq %rax, 0x10(%rsi)
movapd (%rsp), %xmm0
movupd %xmm0, (%rsi)
movq 0x48(%rbx), %rsi
addq $0x18, %rsi
movq %rsi, 0x48(%rbx)
jmp 0x17bc
movq %rsp, %rdx
movq %r15, %rdi
callq 0x3cc4
movq 0x48(%rbx), %rsi
cmpq 0x50(%rbx), %rsi
je 0x17e2
movq 0x10(%rsp), %rax
movq %rax, 0x10(%rsi)
movapd (%rsp), %xmm0
movupd %xmm0, (%rsi)
movq 0x48(%rbx), %rsi
addq $0x18, %rsi
movq %rsi, 0x48(%rbx)
jmp 0x17f1
movq %rsp, %rdx
movq %r15, %rdi
callq 0x3cc4
movq 0x48(%rbx), %rsi
cmpq 0x50(%rbx), %rsi
je 0x1810
movq 0x10(%rsp), %rax
movq %rax, 0x10(%rsi)
movapd (%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x48(%rbx)
jmp 0x181b
movq %rsp, %rdx
movq %r15, %rdi
callq 0x3cc4
movq (%r15), %rax
xorl %ecx, %ecx
movq %rax, %rdx
xorl %esi, %esi
leaq 0x1(%rsi), %rdi
cmpq $0x2, %rsi
movl %edi, %r8d
cmovel %ecx, %r8d
movl %esi, (%rdx)
movl %r8d, 0x4(%rdx)
movl %r8d, 0xc(%rdx)
leaq (%r8,%r8,2), %r8
movl %esi, 0x10(%rax,%r8,8)
movl %esi, 0x78(%rsp,%rsi,4)
addq $0x18, %rdx
movq %rdi, %rsi
cmpq $0x3, %rdi
jne 0x1825
addq $0x28, %rbx
leaq 0x78(%rsp), %rsi
movq %rbx, %rdi
callq 0x33ec
movq (%r15), %rax
xorl %ecx, %ecx
movl %ecx, 0x8(%rax)
movl %ecx, 0x20(%rax)
movl %ecx, 0x38(%rax)
movq %r14, %rdi
callq 0x382a
addq $0xc0, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
movq %r14, %rdi
callq 0x382a
movq %rbx, %rdi
callq 0x11a0
nop