// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Hash_Table.cpp
// Function: print_chain(k_mer_hit*, long long, Chain_Data*, long long)
void print_chain(k_mer_hit* a, long long a_n, Chain_Data* dp, long long topN)
{
    fprintf(stderr, "topN: %lld\n", topN);
    long long max_score = -1, max_i = -1, max_n = 0;;
    long long ss, i, j, current_j;
    kvec_t(long long) si; kv_init(si);
    for (ss = 0; ss < topN && ss < a_n; ss++){
        for (i = 0, max_i = -1, max_score = -1; i < a_n; ++i) {
            for (j = 0; j < (long long)si.n; j++){
                if(i == si.a[j]) break;
            }
            if(j < (long long)si.n) continue;
            if(dp->score[i] > max_score) max_score = dp->score[i], max_i = i;
        }
        if(max_i < 0) continue;
        j = max_i; max_n = 0;
        while (j >= 0)
        {
            current_j = j;
            if(current_j == -1) continue;
            j = dp->pre[j];
            max_n++;
        }

        fprintf(stderr, "\nmax_i: %lld, max_score: %lld, max_n: %lld\n", max_i, max_score, max_n);
        
        j = max_i; 
        while (j >= 0)
        {
            current_j = j;
            if(current_j == -1) continue;

            kv_push(long long, si, current_j);
            j = dp->pre[j];
            fprintf(stderr, "self_offset: %u, offset: %u, cnt: %u, score: %d\n", 
            a[current_j].self_offset, a[current_j].offset, a[current_j].cnt, dp->score[current_j]);
        }
    }
    kv_destroy(si);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r12
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, 0x18(%rsp)
movq 0x24017c(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0x1d04f2(%rip), %rsi    # 0x1e3360
xorl %ebx, %ebx
movq %rcx, %rdx
xorl %eax, %eax
callq 0x22b0
movq %r12, %r8
cmpq %r15, %r12
cmovgeq %r15, %r8
testq %r15, %r15
cmovleq %rbx, %r15
testq %r8, %r8
cmovleq %rbx, %r8
pushq $-0x1
popq %r9
xorl %r12d, %r12d
xorl %r13d, %r13d
movq $0x0, 0x10(%rsp)
xorl %ebx, %ebx
movq %r8, 0x20(%rsp)
cmpq %r8, %r12
je 0x12fda
testq %rbx, %rbx
movl $0x0, %eax
cmovgq %rbx, %rax
movq %r9, %rcx
movq %r9, %rbp
xorl %edx, %edx
cmpq %r15, %rdx
je 0x12efc
xorl %esi, %esi
cmpq %rsi, %rax
je 0x12ee5
leaq 0x1(%rsi), %rdi
cmpq (%r13,%rsi,8), %rdx
movq %rdi, %rsi
jne 0x12ed0
jmp 0x12ef7
movq (%r14), %rsi
movslq (%rsi,%rdx,4), %rsi
cmpq %rsi, %rcx
cmovleq %rsi, %rcx
cmovlq %rdx, %rbp
incq %rdx
jmp 0x12ec9
testq %rbp, %rbp
jns 0x12f06
incq %r12
jmp 0x12eac
xorl %r8d, %r8d
movq %rbp, %rax
testq %rax, %rax
js 0x12f1e
movq 0x8(%r14), %rdx
movq (%rdx,%rax,8), %rax
incq %r8
jmp 0x12f0c
movq 0x2400bb(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0x1d043d(%rip), %rsi    # 0x1e336c
movq %rbp, %rdx
xorl %eax, %eax
callq 0x22b0
testq %rbp, %rbp
movq 0x20(%rsp), %r8
pushq $-0x1
popq %r9
js 0x12f01
movq 0x10(%rsp), %rax
cmpq %rax, %rbx
jne 0x12f81
leaq (%rax,%rax), %rcx
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rcx
movq %rcx, 0x8(%rsp)
leaq (,%rcx,8), %rsi
movq %r13, %rdi
callq 0x2370
movq %rax, %r13
movq 0x8(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %rbp, (%r13,%rbx,8)
incq %rbx
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq (%rcx,%rbp,8), %rcx
movq %rcx, 0x8(%rsp)
movq 0x240040(%rip), %rcx    # 0x252fe0
movq (%rcx), %rdi
movq %rbp, %rsi
shlq $0x4, %rsi
movq 0x18(%rsp), %r8
movl 0x4(%r8,%rsi), %ecx
movl 0x8(%r8,%rsi), %edx
movl 0xc(%r8,%rsi), %r8d
movl (%rax,%rbp,4), %r9d
leaq 0x1d03cf(%rip), %rsi    # 0x1e3398
xorl %eax, %eax
callq 0x22b0
movq 0x8(%rsp), %rbp
jmp 0x12f39
movq %r13, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220