// File: eliebe-5[P]Catmull-clark-subdivision/halfedge.cc
// Function: Mesh::splitEdge(HEEdge*)
void Mesh::splitEdge(HEEdge *edge)
{

    if(edge->split)
        return;

    edge->split = true;
    edge->pair->split = true;
    
    HEEdge *newEdge = edgePool.new_element();
    HEEdge *newPairEdge = edgePool.new_element();
    
    newEdge->split = true;
    newPairEdge->split = true;

    newEdge->uv = (edge->uv + edge->next->uv) * 0.5f;
    newPairEdge->uv = (edge->pair->uv + edge->pair->next->uv) * 0.5f;
    
    HEVert *v = edgePoint(edge);
    
    newEdge->next = edge->next;
    newEdge->pair = edge->pair;
    newEdge->vert = v;
    newEdge->vert->edge = newEdge;
    newEdge->face = edge->face;
    
    newPairEdge->next = edge->pair->next;
    newPairEdge->pair = edge->pair->pair;
    newPairEdge->vert = v;
    newPairEdge->vert->edge = newPairEdge;
    newPairEdge->face = edge->pair->face;
    
    edge->pair->pair = newEdge;
    edge->pair->next = newPairEdge;
    edge->pair = newPairEdge;
    edge->next = newEdge;

    edge->ePt = nullptr;
    newEdge->pair->ePt = nullptr;


}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq 0x50(%rsp), %rax
movq %rax, (%rsp)
movq 0x48(%rsp), %rax
testb $0x1, 0x3c(%rax)
je 0x41a7
jmp 0x43b8
movq (%rsp), %rdi
movq 0x48(%rsp), %rax
movb $0x1, 0x3c(%rax)
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movb $0x1, 0x3c(%rax)
callq 0x63f0
movq (%rsp), %rdi
movq %rax, 0x40(%rsp)
callq 0x63f0
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rax
movb $0x1, 0x3c(%rax)
movq 0x38(%rsp), %rax
movb $0x1, 0x3c(%rax)
movq 0x48(%rsp), %rsi
addq $0x28, %rsi
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rdx
addq $0x28, %rdx
leaq 0x28(%rsp), %rdi
callq 0x66b0
movss 0x7e61(%rip), %xmm0     # 0xc074
movss %xmm0, 0x24(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x24(%rsp), %rdx
callq 0x6700
movq 0x40(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, 0x28(%rax)
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rsi
addq $0x28, %rsi
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rdx
addq $0x28, %rdx
leaq 0x14(%rsp), %rdi
callq 0x66b0
movss 0x7e09(%rip), %xmm0     # 0xc074
movss %xmm0, 0x10(%rsp)
leaq 0x1c(%rsp), %rdi
leaq 0x14(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x6700
movq (%rsp), %rdi
movq 0x38(%rsp), %rax
movq 0x1c(%rsp), %rcx
movq %rcx, 0x28(%rax)
movq 0x48(%rsp), %rsi
callq 0x3fa0
movq %rax, 0x8(%rsp)
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x8(%rsp), %rcx
movq 0x40(%rsp), %rax
movq %rcx, (%rax)
movq 0x40(%rsp), %rcx
movq 0x40(%rsp), %rax
movq (%rax), %rax
movq %rcx, 0x10(%rax)
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x8(%rsp), %rcx
movq 0x38(%rsp), %rax
movq %rcx, (%rax)
movq 0x38(%rsp), %rcx
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq %rcx, 0x10(%rax)
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x10(%rax), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x38(%rsp), %rcx
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x18(%rax)
movq 0x38(%rsp), %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x48(%rsp), %rax
movq $0x0, 0x20(%rax)
movq 0x40(%rsp), %rax
movq 0x8(%rax), %rax
movq $0x0, 0x20(%rax)
addq $0x58, %rsp
retq
nopl (%rax)