// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, 0x18(%rsp)
movq 0x2902b9(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x22c69f(%rip), %rsi    # 0x2313d0
xorl %r13d, %r13d
movq %rcx, %rdx
xorl %eax, %eax
callq 0x22b0
movq %rbx, %rsi
cmpq %r15, %rbx
cmovgeq %r15, %rsi
testq %rsi, %rsi
jle 0x4e7f
pushq $-0x1
popq %rdi
xorl %r12d, %r12d
movq $0x0, 0x8(%rsp)
xorl %r13d, %r13d
xorl %ebx, %ebx
movq %rsi, 0x10(%rsp)
xorl %eax, %eax
movq %rdi, %rbp
movq %rdi, %rcx
testq %r12, %r12
jle 0x4d88
xorl %edx, %edx
cmpq (%r13,%rdx,8), %rax
je 0x4d9a
incq %rdx
cmpq %rdx, %r12
jne 0x4d79
movq (%r14), %rdx
movslq (%rdx,%rax,4), %rdx
cmpq %rdx, %rcx
cmovleq %rdx, %rcx
cmovlq %rax, %rbp
incq %rax
cmpq %r15, %rax
jne 0x4d72
testq %rbp, %rbp
jns 0x4db4
incq %rbx
cmpq %rsi, %rbx
jne 0x4d6a
jmp 0x4e7f
movq 0x8(%r14), %rax
movq %rbp, %rdx
xorl %r8d, %r8d
movq (%rax,%rdx,8), %rdx
incq %r8
testq %rdx, %rdx
jns 0x4dbe
movq 0x29020f(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x22c601(%rip), %rsi    # 0x2313dc
movq %rbp, %rdx
xorl %eax, %eax
callq 0x22b0
cmpq 0x8(%rsp), %r12
jne 0x4e12
leaq (%r12,%r12), %rcx
testq %r12, %r12
pushq $0x2
popq %rax
cmoveq %rax, %rcx
movq %rcx, 0x8(%rsp)
leaq (,%rcx,8), %rsi
movq %r13, %rdi
callq 0x2370
movq %rax, %r13
movq %rbp, (%r13,%r12,8)
incq %r12
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq (%rcx,%rbp,8), %rcx
movq %rcx, 0x20(%rsp)
movq 0x2901af(%rip), %rcx    # 0x294fe0
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 0x22c5ae(%rip), %rsi    # 0x231408
xorl %eax, %eax
callq 0x22b0
movq 0x20(%rsp), %rax
movq %rax, %rbp
testq %rax, %rax
movq 0x10(%rsp), %rsi
pushq $-0x1
popq %rdi
jns 0x4de5
jmp 0x4da7
movq %r13, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220