// File: gchen98[P]macs/algorithm.cpp
// Function: GraphBuilder::getRandomEdgeOnTree(double&, double)
EdgePtr GraphBuilder::getRandomEdgeOnTree(double & dSplitPoint,
double dRandomSpot){
    if (this->bEndGeneConversion && dSplitPoint!=-1.){
        dSplitPoint = gcNewEdge->getBottomNodeRef()->getHeight()+0.;
        return this->gcNewEdge;
    }
    bool found = false;
    double dRunningLength = 0.0;
    EdgePtrVector::iterator it = pEdgeVectorInTree->begin();
    EdgePtr curEdge;
    // the linked list of tree edges are lined up so that a uniform point
    // on the tree can be selected for where the crossover occurs
    unsigned int counter=0;
    while(!found && counter<iTotalTreeEdges){
        curEdge = *it;
        if (!curEdge->bDeleted){
            if (dRandomSpot<dRunningLength+curEdge->getLength()){
                // the random spot is within the current segment
                // the reference var splitpoint returns the position
                // relative to the bottom of this edge that the xover
                // occurs
                dSplitPoint = curEdge->getBottomNodeRef()->getHeight()+
                (dRandomSpot - dRunningLength);
                found = true;
            }else{
                dRunningLength+=curEdge->getLength();
                //if (pConfig->bDebug){
                  //cerr<<"getRandomEdge: running length: "<<dRunningLength<<", random spot "<<dRandomSpot<<"\n"; 
                //}
            }
        }else{
          //if (pConfig->bDebug){
            //cerr<<"getRandomEdge: Sorry edge was deleted\n"; 
          //}
        }
        ++counter;
        ++it;
    }
    if (!found) throw "RandomSpot was out of range for xover";
    return curEdge;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x68(%rbp)
movq %rdi, %rax
movq %rax, -0x60(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
testb $0x1, 0xf9(%rax)
je 0x14ef2
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
movsd 0x1edb0(%rip), %xmm1    # 0x33c48
ucomisd %xmm1, %xmm0
jne 0x14ea2
jp 0x14ea2
jmp 0x14ef2
movq -0x58(%rbp), %rdi
addq $0x110, %rdi            # imm = 0x110
callq 0x1de60
movq %rax, %rdi
callq 0x1deb0
movq %rax, %rdi
callq 0x1ded0
movq %rax, %rdi
callq 0x1df20
movq -0x58(%rbp), %rsi
movq -0x68(%rbp), %rdi
xorps %xmm1, %xmm1
addsd %xmm1, %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, (%rax)
addq $0x110, %rsi            # imm = 0x110
callq 0x1df40
jmp 0x150bf
movq -0x58(%rbp), %rax
movb $0x0, -0x21(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movq 0x18(%rax), %rdi
callq 0x1df80
movq -0x68(%rbp), %rdi
movq %rax, -0x38(%rbp)
movb $0x0, -0x39(%rbp)
callq 0x1dfb0
movl $0x0, -0x40(%rbp)
xorl %eax, %eax
testb $0x1, -0x21(%rbp)
movb %al, -0x69(%rbp)
jne 0x14f3e
movq -0x58(%rbp), %rcx
movl -0x40(%rbp), %eax
cmpl 0x20(%rcx), %eax
setb %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x14f4a
jmp 0x1507b
leaq -0x38(%rbp), %rdi
callq 0x1dfe0
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x1e000
movq -0x68(%rbp), %rdi
callq 0x1de60
testb $0x1, 0x10(%rax)
jne 0x15062
movq -0x68(%rbp), %rdi
movsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
callq 0x1de60
movq %rax, %rdi
callq 0x1e050
movsd %xmm0, -0x78(%rbp)
jmp 0x14fa1
movsd -0x88(%rbp), %xmm1
movsd -0x78(%rbp), %xmm2
movsd -0x80(%rbp), %xmm0
addsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x15033
movq -0x68(%rbp), %rdi
callq 0x1de60
movq %rax, %rdi
callq 0x1deb0
movq %rax, -0x90(%rbp)
jmp 0x14fd7
movq -0x90(%rbp), %rdi
callq 0x1ded0
movq %rax, %rdi
callq 0x1df20
movsd %xmm0, -0x98(%rbp)
jmp 0x14ff5
movsd -0x98(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
subsd -0x30(%rbp), %xmm1
addsd %xmm1, %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, (%rax)
movb $0x1, -0x21(%rbp)
jmp 0x15060
movq -0x68(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x1e090
jmp 0x150cc
movq -0x68(%rbp), %rdi
callq 0x1de60
movq %rax, %rdi
callq 0x1e050
movsd %xmm0, -0xa0(%rbp)
jmp 0x1504e
movsd -0xa0(%rbp), %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x15064
jmp 0x15064
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x1e070
jmp 0x14f23
testb $0x1, -0x21(%rbp)
jne 0x150aa
movl $0x8, %edi
callq 0x4130
movq %rax, %rdi
leaq 0x1ebeb(%rip), %rax     # 0x33c80
movq %rax, (%rdi)
movq 0x33f19(%rip), %rsi     # 0x48fb8
xorl %eax, %eax
movl %eax, %edx
callq 0x44c0
jmp 0x150d5
movb $0x1, -0x39(%rbp)
testb $0x1, -0x39(%rbp)
jne 0x150bd
movq -0x68(%rbp), %rdi
callq 0x1e090
jmp 0x150bf
movq -0x60(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x44e0
nopw %cs:(%rax,%rax)