// File: chhylp123[P]hifiasm/Hash_Table.cpp
// Function: lchain_dp_trace(k_mer_hit*, long, long, double, long)
uint64_t lchain_dp_trace(k_mer_hit* a, int64_t a_n, int64_t max_lgap, double sgap_rate, int64_t sgap)
{
    // fprintf(stderr, "[M::%s::] a_n::%ld\n", __func__, a_n);
    if(a_n <= 0) return 0;
    int64_t i, st, occ = 0; 

    for (i = 1, st = 0; i <= a_n; ++i) {
        // fprintf(stderr, "[M::%s::i->%ld] q::%u, t::%u, cnt::%u, readID::%u\n", __func__, 
        // i-1, a[i-1].self_offset, a[i-1].offset, a[i-1].cnt, a[i-1].readID);
        if((i == a_n) || (is_alnw(a[i]))) {///[st, i)
            if(i > st) {
                occ += filter_bad_seed_dp((st>0)?&(a[st-1]):NULL, (i<a_n)?&(a[i]):NULL, a, a_n, max_lgap, sgap_rate, sgap);
            }
            st = i+1;
        }
    }

    if(occ) {
        for (i = occ = 0; i < a_n; ++i) {
            if(a[i].self_offset == ((uint32_t)-1)) continue;
            a[occ++] = a[i];
        }
        a_n = occ;
    }
    return a_n;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
cmpq $0x0, -0x18(%rbp)
jg 0x2af61
movq $0x0, -0x8(%rbp)
jmp 0x2b0ed
movq $0x0, -0x48(%rbp)
movq $0x1, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jg 0x2b060
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
je 0x2afb2
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
jne 0x2b04d
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jle 0x2b041
cmpq $0x0, -0x40(%rbp)
jle 0x2afe0
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
subq $0x1, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
jmp 0x2afe8
xorl %eax, %eax
movq %rax, -0x50(%rbp)
jmp 0x2afe8
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0x2b00f
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
jmp 0x2b017
xorl %eax, %eax
movq %rax, -0x60(%rbp)
jmp 0x2b017
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movsd -0x28(%rbp), %xmm0
movq -0x30(%rbp), %r9
callq 0x2ace0
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x2b04f
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2af79
cmpq $0x0, -0x48(%rbp)
je 0x2b0e5
movq $0x0, -0x48(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0x2b0dd
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x8(%rax)
jne 0x2b098
jmp 0x2b0cf
movq -0x10(%rbp), %rcx
movq -0x38(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq -0x48(%rbp), %rdx
movq %rdx, %rsi
addq $0x1, %rsi
movq %rsi, -0x48(%rbp)
shlq $0x4, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2b077
movq -0x48(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)