// File: gchen98[P]macs/datastructures.cpp
// Function: GraphBuilder::addEdge(boost::shared_ptr<Edge>&)
void GraphBuilder::addEdge(EdgePtr & edge){
    unsigned int iPopulation = edge->getBottomNodeRef()->getPopulation();
    //if(pConfig->bDebug) cerr<<"DEBUG addEdge: iPopulation: "<<iPopulation<<" and pEdgeVectorByPop size "<<pEdgeVectorByPop->size()<<endl;
    this->pEdgeListInARG->push_back(edge);
    while (iPopulation>=pEdgeVectorByPop->size()){
        this->pEdgeVectorByPop->push_back(EdgePtrVector());
        this->pVectorIndicesToRecycle->push_back(EdgeIndexQueue());
        if(pConfig->bDebug)cerr<<"DEBUG! addEdge: Adding pop "<<iPopulation<<" has edge vector size: "<<pEdgeVectorByPop->size()<<endl;
//        if(pConfig->bDebug)cerr<<"DEBUG! addEdge: Just added. Pop "<<iPopulation<<" has edge vector size: "<<pEdgeVectorByPop->at(iPopulation).size()<<endl;
        //cerr<<"Attempting to add edge of population "<<iPopulation<<" when the number of available population edge pools is only "<<pEdgeVectorByPop->size()<<". It is recommended that you increase the migration rates and/or number of sampled chromosomes."<<endl;
        //for(uint i=0;i<pEdgeVectorByPop->size();++i){
         //cerr<<"Pop "<<i<<" has edge vector size: "<<pEdgeVectorByPop->at(i).size()<<endl;
        //}
         // throw "Data structure integrity error.";
        //}
      //}
    }
    if (iPopulation>=pEdgeVectorByPop->size()){
      if(pConfig->bDebug) cerr<<"DEBUG! addEdge: Still not added! iPopulation: "<<iPopulation<<" and pEdgeVectorByPop size "<<pEdgeVectorByPop->size()<<endl;
      throw "Something wrong with while loop";
    }
    
    // Insert into the vector allowing for random access
    EdgePtrVector & pEdgeVector = this->pEdgeVectorByPop->
    at(iPopulation);
    EdgeIndexQueue & pVectorIndicesToRecycle = this->pVectorIndicesToRecycle->
    at(iPopulation);
    if (pVectorIndicesToRecycle.empty()){
        pEdgeVector.push_back(edge);
        //if(pConfig->bDebug) cerr<<"DEBUG: pEdgeVector for pop "<<iPopulation<<" is now size: "<<pEdgeVector.size()<<endl;
    }else{
        int iIndex = pVectorIndicesToRecycle.front();
        pVectorIndicesToRecycle.pop();
        pEdgeVector[iIndex] = edge;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1de60
movq %rax, %rdi
callq 0x1deb0
movq %rax, %rdi
callq 0x1ded0
movq %rax, %rdi
callq 0x1e0b0
movw %ax, %cx
movq -0xb0(%rbp), %rax
movswl %cx, %ecx
movl %ecx, -0x14(%rbp)
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x1f2a0
movq -0xb0(%rbp), %rax
movl -0x14(%rbp), %ecx
movq %rcx, -0xb8(%rbp)
movq 0x98(%rax), %rdi
callq 0x20c20
movq %rax, %rcx
movq -0xb8(%rbp), %rax
cmpq %rcx, %rax
jb 0x2a132
movq -0xb0(%rbp), %rax
movq 0x98(%rax), %rax
movq %rax, -0xc8(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x30(%rbp)
movq $0x0, -0x20(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x2bbd0
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0x2bba0
jmp 0x2a025
leaq -0x30(%rbp), %rdi
callq 0x2b9b0
movq -0xb0(%rbp), %rax
movq 0xa0(%rax), %rax
movq %rax, -0xd8(%rbp)
leaq -0x90(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x2bc20
movq -0xd8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x2bbf0
jmp 0x2a06b
leaq -0x90(%rbp), %rdi
callq 0x2bc50
movq -0xb0(%rbp), %rax
movq 0x8(%rax), %rax
testb $0x1, 0x48(%rax)
je 0x2a12d
movq 0x1ef5d(%rip), %rdi     # 0x48ff0
leaq 0xa71b(%rip), %rsi      # 0x347b5
callq 0x42b0
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x43e0
movq %rax, %rdi
leaq 0xa71d(%rip), %rsi      # 0x347d1
callq 0x42b0
movq %rax, %rcx
movq -0xb0(%rbp), %rax
movq %rcx, -0xe0(%rbp)
movq 0x98(%rax), %rdi
callq 0x20c20
movq -0xe0(%rbp), %rdi
movq %rax, %rsi
callq 0x4090
movq %rax, %rdi
movq 0x1eec1(%rip), %rsi     # 0x48fb0
callq 0x4300
jmp 0x2a12d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2b9b0
jmp 0x2a2bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x2bc50
jmp 0x2a2bd
jmp 0x29fac
movq -0xb0(%rbp), %rax
movl -0x14(%rbp), %ecx
movq %rcx, -0xe8(%rbp)
movq 0x98(%rax), %rdi
callq 0x20c20
movq %rax, %rcx
movq -0xe8(%rbp), %rax
cmpq %rcx, %rax
jb 0x2a202
movq -0xb0(%rbp), %rax
movq 0x8(%rax), %rax
testb $0x1, 0x48(%rax)
je 0x2a1db
movq 0x1ee76(%rip), %rdi     # 0x48ff0
leaq 0xa668(%rip), %rsi      # 0x347e9
callq 0x42b0
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x43e0
movq %rax, %rdi
leaq 0xa67d(%rip), %rsi      # 0x34818
callq 0x42b0
movq %rax, %rcx
movq -0xb0(%rbp), %rax
movq %rcx, -0xf0(%rbp)
movq 0x98(%rax), %rdi
callq 0x20c20
movq -0xf0(%rbp), %rdi
movq %rax, %rsi
callq 0x4090
movq %rax, %rdi
movq 0x1edda(%rip), %rsi     # 0x48fb0
callq 0x4300
movl $0x8, %edi
callq 0x4130
movq %rax, %rdi
leaq 0xa645(%rip), %rax      # 0x34834
movq %rax, (%rdi)
movq 0x1edbf(%rip), %rsi     # 0x48fb8
xorl %eax, %eax
movl %eax, %edx
callq 0x44c0
movq -0xb0(%rbp), %rax
movq 0x98(%rax), %rdi
movl -0x14(%rbp), %eax
movl %eax, %esi
callq 0x1e0d0
movq %rax, %rcx
movq -0xb0(%rbp), %rax
movq %rcx, -0x98(%rbp)
movq 0xa0(%rax), %rdi
movl -0x14(%rbp), %eax
movl %eax, %esi
callq 0x1e110
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rdi
callq 0x2bdc0
testb $0x1, %al
jne 0x2a255
jmp 0x2a267
movq -0x98(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2bde0
jmp 0x2a2b4
movq -0xa0(%rbp), %rdi
callq 0x2be50
movl (%rax), %eax
movl %eax, -0xa4(%rbp)
movq -0xa0(%rbp), %rdi
callq 0x2be70
movq -0x10(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x98(%rbp), %rdi
movslq -0xa4(%rbp), %rsi
callq 0x1e190
movq -0xf8(%rbp), %rsi
movq %rax, %rdi
callq 0x1e000
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x44e0
nopw %cs:(%rax,%rax)