// File: /workspace/github_cpp_makefile_star2_O1/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 0xe39d
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 -0x10c(%rip), %rcx      # 0xe147
movq %r14, %rdi
movq %rbp, %rsi
callq 0xe763
leaq 0x8(%r14), %r12
cmpq $0x81, %r15
jl 0xe334
movq %rbp, 0x10(%rsp)
movl $0x8, %r13d
movq %r12, %rbp
movq %r14, %r8
movq %r8, %rcx
leaq (%r14,%r13), %r8
movq (%r14,%r13), %r15
movq (%r14), %rdx
movl 0x14(%r15), %eax
cmpl 0x14(%rdx), %eax
jge 0xe2b4
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %r8, 0x8(%rsp)
callq 0x5700
movq 0x8(%rsp), %r8
movq %r14, %rcx
jmp 0xe2d9
movq (%rcx), %rdx
movq %r8, %rcx
cmpl 0x14(%rdx), %eax
jge 0xe2d9
movq %rbp, %rdx
leaq -0x8(%rdx), %rcx
movq -0x10(%rdx), %rsi
movq -0x8(%rdx), %rdi
movq %rdi, (%rdx)
movq %rcx, %rdx
cmpl 0x14(%rsi), %eax
jl 0xe2c2
movq %r15, (%rcx)
addq $0x8, %r13
addq $0x8, %rbp
cmpq $0x80, %r13
jne 0xe280
subq $-0x80, %r14
movq 0x10(%rsp), %r9
cmpq %r9, %r14
je 0xe39d
movq -0x8(%r14), %rsi
movq (%r14), %rax
movl 0x14(%rax), %ecx
movq %r14, %rdx
cmpl 0x14(%rsi), %ecx
jge 0xe32b
movq %r14, %rsi
leaq -0x8(%rsi), %rdx
movq -0x10(%rsi), %rdi
movq -0x8(%rsi), %r8
movq %r8, (%rsi)
movq %rdx, %rsi
cmpl 0x14(%rdi), %ecx
jl 0xe314
movq %rax, (%rdx)
addq $0x8, %r14
jmp 0xe2f6
cmpq %rbp, %r12
je 0xe39d
movq %r14, %r13
movq %r13, %rdi
movq %r12, %r13
movq (%r12), %r15
movq (%r14), %rcx
movl 0x14(%r15), %eax
cmpl 0x14(%rcx), %eax
jge 0xe36c
movq %r13, %rdx
subq %r14, %rdx
subq %rdx, %rdi
addq $0x10, %rdi
movq %r14, %rsi
callq 0x5700
movq %r14, %rcx
jmp 0xe391
movq (%rdi), %rdx
movq %r13, %rcx
cmpl 0x14(%rdx), %eax
jge 0xe391
movq %r13, %rdx
leaq -0x8(%rdx), %rcx
movq -0x10(%rdx), %rsi
movq -0x8(%rdx), %rdi
movq %rdi, (%rdx)
movq %rcx, %rdx
cmpl 0x14(%rsi), %eax
jl 0xe37a
movq %r15, (%rcx)
leaq 0x8(%r13), %r12
cmpq %rbp, %r12
jne 0xe33c
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 0xe0cc
movq 0x18(%rbx), %rax
movq %rax, %rcx
subq 0x10(%rbx), %rcx
cmpq $0x9, %rcx
jb 0xe46c
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 0xe433
movsd 0x8(%rdx), %xmm1
maxsd %xmm0, %xmm1
movq 0x28(%rdi), %rsi
cmpq 0x30(%rdi), %rsi
je 0xe41a
movq %rdx, (%rsi)
addq $0x8, 0x28(%rdi)
movapd %xmm1, %xmm0
jmp 0xe433
leaq (%rcx,%rax,8), %rdx
addq $0x20, %rdi
movsd %xmm1, 0x8(%rsp)
callq 0xe628
movsd 0x8(%rsp), %xmm0
decq %r12
cmpq $0x1, %r12
jg 0xe3e0
movq 0x10(%rbx), %rax
movq (%rax,%r14,8), %rax
addsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rax)
movq 0x18(%rbx), %rax
movq %rax, %rcx
subq 0x10(%rbx), %rcx
incq %r14
sarq $0x3, %rcx
incq %r15
cmpq %r14, %rcx
ja 0xe3d9
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