// File: /workspace/github_cpp_makefile_star2_O1/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, 0x20(%rsp)
movq 0x285306(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0x22064c(%rip), %rsi    # 0x225330
xorl %r13d, %r13d
movq %rcx, %rdx
xorl %eax, %eax
callq 0x22b0
movq %rbx, %rsi
cmpq %r15, %rbx
cmovgeq %r15, %rsi
testq %rsi, %rsi
jle 0x4e3f
pushq $-0x1
popq %rdi
xorl %r12d, %r12d
movq $0x0, 0x10(%rsp)
xorl %r13d, %r13d
xorl %ebx, %ebx
movq %rsi, 0x18(%rsp)
xorl %eax, %eax
movq %rdi, %rbp
movq %rdi, %rcx
testq %r12, %r12
jle 0x4d3b
xorl %edx, %edx
cmpq (%r13,%rdx,8), %rax
je 0x4d4d
incq %rdx
cmpq %rdx, %r12
jne 0x4d2c
movq (%r14), %rdx
movslq (%rdx,%rax,4), %rdx
cmpq %rdx, %rcx
cmovleq %rdx, %rcx
cmovlq %rax, %rbp
incq %rax
cmpq %r15, %rax
jne 0x4d25
testq %rbp, %rbp
jns 0x4d67
incq %rbx
cmpq %rsi, %rbx
jne 0x4d1d
jmp 0x4e3f
movq 0x8(%r14), %rax
movq %rbp, %rdx
xorl %r8d, %r8d
movq (%rax,%rdx,8), %rdx
incq %r8
testq %rdx, %rdx
jns 0x4d71
movq 0x28525c(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0x2205ae(%rip), %rsi    # 0x22533c
movq %rbp, %rdx
xorl %eax, %eax
callq 0x22b0
movq 0x10(%rsp), %rax
cmpq %rax, %r12
jne 0x4dd2
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,%r12,8)
incq %r12
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq (%rcx,%rbp,8), %rcx
movq %rcx, 0x8(%rsp)
movq 0x2851ef(%rip), %rcx    # 0x289fe0
movq (%rcx), %rdi
movq %rbp, %rsi
shlq $0x4, %rsi
movq 0x20(%rsp), %r8
movl 0x4(%r8,%rsi), %ecx
movl 0x8(%r8,%rsi), %edx
movl 0xc(%r8,%rsi), %r8d
movl (%rax,%rbp,4), %r9d
leaq 0x22054e(%rip), %rsi    # 0x225368
xorl %eax, %eax
callq 0x22b0
movq 0x8(%rsp), %rax
movq %rax, %rbp
testq %rax, %rax
movq 0x18(%rsp), %rsi
pushq $-0x1
popq %rdi
jns 0x4d98
jmp 0x4d5a
movq %r13, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220