// File: /workspace/github_cpp_makefile_star2_O3/zeeev[P]DASVC/src/chain.cpp
// Function: chain::buildLinks()
bool chain::buildLinks(void){

    // sorted by end position
    sort(nodes.begin(), nodes.end(), _endCmp);
    // adding sink
    addAlignment(nodes.back()->end + 1, nodes.back()->end +2, 0);

    for(int i = 1 ; i < nodes.size() ; i++){

        double maxScore = 0;
        for(int j = i - 1; j >= 0; j--){
            if(nodes[j]->end <= nodes[i]->start){
                double tmp_score = nodes[j]->overallScore ;
                if(tmp_score > maxScore){
                    maxScore = tmp_score;
                }
                nodes[i]->children.push_back(nodes[j]);
            }
        }
        nodes[i]->overallScore += maxScore;
    }

    last = nodes.back();

    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x10(%rdi), %r14
movq 0x18(%rdi), %rbp
cmpq %rbp, %r14
je 0xe30c
movq %rbp, %r15
subq %r14, %r15
movq %r15, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0x110(%rip), %rcx      # 0xe0c7
movq %r14, %rdi
movq %rbp, %rsi
callq 0xe6c5
leaq 0x8(%r14), %r12
cmpq $0x81, %r15
jl 0xe2aa
movq %rbp, 0x10(%rsp)
movl $0x8, %r13d
movq %r12, %rbp
movq %r14, %rsi
movq %rsi, %rcx
leaq (%r14,%r13), %rsi
movq (%r14,%r13), %r15
movq (%r14), %rdx
movl 0x14(%r15), %eax
cmpl 0x14(%rdx), %eax
jge 0xe238
movq %r12, %rdi
movq %rsi, 0x8(%rsp)
movq %r14, %rsi
movq %r13, %rdx
callq 0x5700
movq 0x8(%rsp), %rsi
movq %r14, %rcx
jmp 0xe256
movq (%rcx), %rdx
movq %rsi, %rcx
cmpl 0x14(%rdx), %eax
jge 0xe256
movq %rbp, %rcx
movq %rdx, (%rcx)
movq -0x10(%rcx), %rdx
addq $-0x8, %rcx
cmpl 0x14(%rdx), %eax
jl 0xe246
movq %r15, (%rcx)
addq $0x8, %r13
addq $0x8, %rbp
cmpq $0x80, %r13
jne 0xe204
subq $-0x80, %r14
movq 0x10(%rsp), %rdi
cmpq %rdi, %r14
je 0xe30c
movq -0x8(%r14), %rcx
movq (%r14), %rax
movl 0x14(%rax), %edx
movq %r14, %rsi
cmpl 0x14(%rcx), %edx
jge 0xe2a1
movq %r14, %rsi
movq %rcx, (%rsi)
movq -0x10(%rsi), %rcx
addq $-0x8, %rsi
cmpl 0x14(%rcx), %edx
jl 0xe291
movq %rax, (%rsi)
addq $0x8, %r14
jmp 0xe273
cmpq %rbp, %r12
je 0xe30c
movq %r14, %r13
movq %r13, %rdi
movq %r12, %r13
movq (%r12), %r15
movq (%r14), %rcx
movl 0x14(%r15), %eax
cmpl 0x14(%rcx), %eax
jge 0xe2e2
movq %r13, %rdx
subq %r14, %rdx
subq %rdx, %rdi
addq $0x10, %rdi
movq %r14, %rsi
callq 0x5700
movq %r14, %rcx
jmp 0xe300
movq (%rdi), %rdx
movq %r13, %rcx
cmpl 0x14(%rdx), %eax
jge 0xe300
movq %r13, %rcx
movq %rdx, (%rcx)
movq -0x10(%rcx), %rdx
addq $-0x8, %rcx
cmpl 0x14(%rdx), %eax
jl 0xe2f0
movq %r15, (%rcx)
leaq 0x8(%r13), %r12
cmpq %rbp, %r12
jne 0xe2b2
movq 0x18(%rbx), %rax
movq -0x8(%rax), %rax
movl 0x14(%rax), %edx
leal 0x1(%rdx), %esi
addl $0x2, %edx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0xe048
movq 0x18(%rbx), %rax
movq %rax, %rcx
subq 0x10(%rbx), %rcx
cmpq $0x9, %rcx
jb 0xe3da
movl $0x1, %r14d
movl $0x2, %r15d
xorpd %xmm0, %xmm0
movq %r15, %r12
leal -0x2(%r12), %eax
movq 0x10(%rbx), %rcx
movq (%rcx,%rax,8), %rdx
movl 0x14(%rdx), %esi
movq (%rcx,%r14,8), %rdi
cmpl 0x10(%rdi), %esi
jg 0xe3a2
movsd 0x8(%rdx), %xmm1
maxsd %xmm0, %xmm1
movq 0x28(%rdi), %rsi
cmpq 0x30(%rdi), %rsi
je 0xe389
movq %rdx, (%rsi)
addq $0x8, 0x28(%rdi)
movapd %xmm1, %xmm0
jmp 0xe3a2
leaq (%rcx,%rax,8), %rdx
addq $0x20, %rdi
movsd %xmm1, 0x8(%rsp)
callq 0xe58a
movsd 0x8(%rsp), %xmm0
decq %r12
cmpq $0x1, %r12
jg 0xe34f
movq 0x10(%rbx), %rcx
movq (%rcx,%r14,8), %rax
addsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rax)
incq %r14
movq 0x18(%rbx), %rax
movq %rax, %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
incq %r15
cmpq %r14, %rdx
ja 0xe348
movq -0x8(%rax), %rax
movq %rax, 0x8(%rbx)
movb $0x1, %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop