// File: /workspace/github_cpp_makefile_star2_O3/gchen98[P]macs/algorithm.cpp
// Function: GraphBuilder::markEdgesAbove(bool, bool, boost::shared_ptr<Edge>&, unsigned int&)
bool GraphBuilder::markEdgesAbove(bool bFirstSample,bool  bCalledFromParent,
EdgePtr & selectedEdge, unsigned int & iSampleIndex){
    if (bFirstSample || bCalledFromParent || !selectedEdge->bInCurrentTree){
        if (!selectedEdge->bInCurrentTree) addEdgeToCurrentTree(selectedEdge);
        NodePtr topNode = selectedEdge->getTopNodeRef();
        double dTopHeight = topNode->getHeight();
        double dproposedOriginHt = localMRCA->getHeight();
        if (dTopHeight>=dproposedOriginHt &&
        topNode->getType()==Node::COAL){
            // If we reach at least as high as proposed MRCA
            // save this edge as the vector
            // so we don't traverse from the bottom
            pTreeEdgesToCoalesceArray[iSampleIndex]=selectedEdge;
            if (bFirstSample){
                if (dTopHeight>dproposedOriginHt)
                    // establish a new proposed MRCA
                    // for susequent samples to try reaching
                    localMRCA = topNode;
                // proceed to the next sampled node
                return true;
            }else{
                if (dTopHeight>dproposedOriginHt){
                    // if we surpassed a MRCA height previously proposed
                    // upgrade the proposed MRCA height
                    localMRCA = topNode;
                    // start over in the loop to sample 0
                    return false;
                }else{
                    if (localMRCA!=topNode){
                        cerr<<"proposed grandMRCA != top Node\n";
                    }
                    // here the current height is EQUAL to the proposed MRCA,
                    // this is good and we can proceed to the next sampled node
                    return true;
                }
            }
        }
        else{
            // if we come across a crossover, there are two edges above,
            // we choose the one with the more recent (larger) tree label
            if (topNode->getType()==Node::XOVER){
                EdgePtr edge0 =topNode->getTopEdgeByIndex(0);
                EdgePtr edge1 =topNode->getTopEdgeByIndex(1);
                int iter0=-1,iter1=-1;
                if (edge0!=NULL) iter0=edge0->iGraphIteration;
                if (edge1!=NULL) iter1=edge1->iGraphIteration;
                if (iter0==-1 && iter1==-1) throw "In mark edges above, both edges above xover were missing";
                EdgePtr & nextEdge = (iter0>iter1)? edge0:edge1;
                return markEdgesAbove(bFirstSample,false,nextEdge,
                iSampleIndex);
            // for other nodes, just choose the single edge above it
            // recursively call this method again
            }else{
                EdgePtr edge = topNode->getTopEdgeByIndex(0);
                return markEdgesAbove(bFirstSample,false,edge,
                iSampleIndex);
            }
        }
    }else{
        // the selected edge was in the current tree already and this is for
        // a sampled node after the first one and was called by this method.
        // the latter condition implies that we previously explored up this
        // node.  in this case, save time and proceed to the next node
        return true;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, %r15
movq %rcx, %r13
movl %esi, %ebp
movq %rdi, %r14
orl %esi, %edx
movq (%rcx), %rax
je 0xa1b8
testq %rax, %rax
jne 0xa1ce
jmp 0xa466
testq %rax, %rax
je 0xa466
movb $0x1, %r12b
cmpb $0x0, 0x12(%rax)
jne 0xa430
cmpb $0x1, 0x12(%rax)
je 0xa1ec
movq %r14, %rdi
movq %r13, %rsi
callq 0x14086
movq (%r13), %rax
testq %rax, %rax
je 0xa466
movq 0x18(%rax), %rbx
movq %rbx, 0x10(%rsp)
testq %rbx, %rbx
je 0xa447
incq 0x8(%rbx)
movq 0x40(%r14), %rax
testq %rax, %rax
je 0xa447
movsd 0x70(%rbx), %xmm0
movsd 0x70(%rax), %xmm1
ucomisd %xmm1, %xmm0
setae %cl
movl 0x64(%rbx), %eax
testl %eax, %eax
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0xa281
movsd %xmm1, 0x18(%rsp)
movsd %xmm0, 0x20(%rsp)
movl (%r15), %edi
shlq $0x4, %rdi
addq 0xb8(%r14), %rdi
addq $0x40, %r14
movq %r13, %rsi
callq 0x10736
testb %bpl, %bpl
je 0xa2c2
movb $0x1, %r12b
movsd 0x20(%rsp), %xmm0
ucomisd 0x18(%rsp), %xmm0
jbe 0xa417
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x10770
jmp 0xa417
cmpl $0x1, %eax
jne 0xa2e5
movq $0x0, (%rsp)
movq 0x28(%rbx), %rcx
movq %rcx, 0x8(%rsp)
testq %rcx, %rcx
je 0xa34c
movl 0x8(%rcx), %eax
testl %eax, %eax
je 0xa343
leal 0x1(%rax), %edx
lock
cmpxchgl %edx, 0x8(%rcx)
jne 0xa2a3
movq 0x20(%rbx), %rcx
movq %rcx, (%rsp)
jmp 0xa34e
movsd 0x20(%rsp), %xmm0
ucomisd 0x18(%rsp), %xmm0
jbe 0xa31a
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x10770
xorl %r12d, %r12d
jmp 0xa417
movq $0x0, (%rsp)
movq 0x28(%rbx), %rcx
movq %rcx, 0x8(%rsp)
testq %rcx, %rcx
je 0xa38a
movl 0x8(%rcx), %eax
testl %eax, %eax
je 0xa381
leal 0x1(%rax), %edx
lock
cmpxchgl %edx, 0x8(%rcx)
jne 0xa302
movq 0x20(%rbx), %rax
movq %rax, (%rsp)
jmp 0xa38a
cmpq %rbx, (%r14)
je 0xa442
movb $0x1, %r12b
movq 0x15cc3(%rip), %rdi     # 0x1fff0
leaq 0xe9c3(%rip), %rsi      # 0x18cf7
movl $0x1f, %edx
callq 0x32a0
jmp 0xa417
movq $0x0, 0x8(%rsp)
xorl %ecx, %ecx
movq $0x0, 0x28(%rsp)
movq 0x38(%rbx), %rdx
movq %rdx, 0x30(%rsp)
testq %rdx, %rdx
je 0xa3b4
movl 0x8(%rdx), %eax
testl %eax, %eax
je 0xa3ab
leal 0x1(%rax), %esi
lock
cmpxchgl %esi, 0x8(%rdx)
jne 0xa368
movq 0x30(%rbx), %rdx
movq %rdx, 0x28(%rsp)
jmp 0xa3b6
movq $0x0, 0x8(%rsp)
leaq 0x8(%rsp), %r13
movzbl %bpl, %esi
movq %rsp, %rcx
movq %r14, %rdi
xorl %edx, %edx
movq %r15, %r8
callq 0xa18e
movl %eax, %r12d
movq %r13, %rdi
jmp 0xa412
movq $0x0, 0x30(%rsp)
xorl %edx, %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
testq %rcx, %rcx
je 0xa3c8
movl 0x14(%rcx), %esi
testq %rdx, %rdx
je 0xa3d0
movl 0x14(%rdx), %eax
leaq 0x30(%rsp), %r13
cmpl $-0x1, %esi
jne 0xa3e3
cmpl $-0x1, %eax
je 0xa485
cmpl %eax, %esi
movq %rsp, %rax
leaq 0x28(%rsp), %rcx
cmovgq %rax, %rcx
movzbl %bpl, %esi
movq %r14, %rdi
xorl %edx, %edx
movq %r15, %r8
callq 0xa18e
movl %eax, %r12d
movq %r13, %rdi
callq 0x10d5e
leaq 0x8(%rsp), %rdi
callq 0x10d5e
movq 0x10(%rsp), %rbx
testq %rbx, %rbx
je 0xa430
decq 0x8(%rbx)
jne 0xa430
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %r12b
jmp 0xa421
leaq 0xe6aa(%rip), %rdi      # 0x18af8
leaq 0xe6ab(%rip), %rsi      # 0x18b00
leaq 0xf09f(%rip), %rcx      # 0x194fb
movl $0xc7, %edx
callq 0x3170
leaq 0xe68b(%rip), %rdi      # 0x18af8
leaq 0xeff2(%rip), %rsi      # 0x19466
leaq 0xf017(%rip), %rcx      # 0x19492
movl $0x2d8, %edx            # imm = 0x2D8
callq 0x3170
movl $0x8, %edi
callq 0x3100
leaq 0xe881(%rip), %rcx      # 0x18d17
movq %rcx, (%rax)
movq 0x15b10(%rip), %rsi     # 0x1ffb0
movq %rax, %rdi
xorl %edx, %edx
callq 0x33d0
jmp 0xa4b4
movq %rax, %r14
movq %r13, %rdi
jmp 0xa4c4
movq %rax, %r14
movq %r13, %rdi
callq 0x10d5e
leaq 0x8(%rsp), %rdi
callq 0x10d5e
jmp 0xa4d3
movq %rax, %r14
movq 0x10(%rsp), %rbx
testq %rbx, %rbx
je 0xa4e7
decq 0x8(%rbx)
jne 0xa4e7
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
movq %r14, %rdi
callq 0x33f0
nop