// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: debug_backtrace_step_err(unsigned long, ul_ov_t*, rtrace_t*, ul_idx_t const*, char*, UC_Read*, overlap_region*, bit_extz_t*, double)
void debug_backtrace_step_err(uint64_t rid, ul_ov_t *aln, rtrace_t *tc, const ul_idx_t *uref, char* qstr, UC_Read *tu, overlap_region *o, bit_extz_t *exz, double e_rate)
{
    // if(aln->qs == 0 && aln->qe == 3013 && aln->ts == 28965 && aln->te == 31993) {
        // fprintf(stderr, "\n[M::%s::] q::[%u, %u), t::[%u, %u), tot_e::%u, cid::[%d, %d], cq::[%u, %u), ct::[%u, %u), pfx_e::%d, sfx_e::%d, mid_e::%d\n", 
        //                 __func__, aln->qs, aln->qe, aln->ts, aln->te, aln->sec, tc->c_wsid, tc->c_weid,
        //                 tc->c_qs, tc->c_qe, tc->c_ts, tc->c_te, tc->pfx_e, tc->sfx_e, tc->mid_e);
        int64_t k, err, qs = aln->qs, qe = aln->qe, err0; rtrace_iter it;
        k = qe; it.k = INT32_MAX;
        err0 = get_rid_backward_cigar_err(&it, aln, NULL, tc, uref, qstr, tu, NULL, o, exz, e_rate, k); 
        err = get_rid_backward_cigar_err(&it, aln, NULL, tc, uref, qstr, tu, NULL, o, exz, e_rate, k); 
        assert(err == err0); 
        for (k = qe, it.k = INT32_MAX, err0 = 0; k >= qs; k-=8) {
            err = get_rid_backward_cigar_err(&it, aln, NULL, tc, uref, qstr, tu, NULL, o, exz, e_rate, k);  
            // if(!(err >= 0 && err >= err0)) {
            //     fprintf(stderr, "[M::%s::rid->%lu] q::[%u, %u), t::[%u, %u), tot_e::%u, cid::[%d, %d], cq::[%u, %u), ct::[%u, %u)\n", 
            //             __func__, rid, aln->qs, aln->qe, aln->ts, aln->te, aln->sec, tc->c_wsid, tc->c_weid,
            //             tc->c_qs, tc->c_qe, tc->c_ts, tc->c_te);
            //     fprintf(stderr, "[M::%s::] q::[%ld, %ld), err::%ld, err0::%ld\n", __func__, k, qe, err, err0);   
            // }
            // fprintf(stderr, "[M::%s::] q::[%ld, %ld), err::%ld\n", __func__, k, qe, err); 
            assert(err >= 0 && err >= err0); 
            err0 = err;  
        }
        k = qs;
        err = get_rid_backward_cigar_err(&it, aln, NULL, tc, uref, qstr, tu, NULL, o, exz, e_rate, k); 
        // if(!(err >= 0 && err >= err0)) {
        //     fprintf(stderr, "[M::%s::rid->%lu] q::[%u, %u), t::[%u, %u), tot_e::%u, cid::[%d, %d], cq::[%u, %u), ct::[%u, %u)\n", 
        //             __func__, rid, aln->qs, aln->qe, aln->ts, aln->te, aln->sec, tc->c_wsid, tc->c_weid,
        //             tc->c_qs, tc->c_qe, tc->c_ts, tc->c_te);
        //     fprintf(stderr, "[M::%s::] q::[%ld, %ld), err::%ld, err0::%ld\n", __func__, k, qe, err, err0);   
        // }
        // fprintf(stderr, "[M::%s::] q::[%ld, %ld), err::%ld, exz->err::%d, exz->cigar.n::%d\n", 
        // __func__, qs, qe, err, exz->err, (int32_t)exz->cigar.n);    
        assert(err >= 0 && err >= err0); 
        if(!(err == (int64_t)aln->sec)) {
            fprintf(stderr, "[M::%s::rid->%lu] q::[%u, %u), t::[%u, %u), tot_e::%u, cid::[%d, %d], cq::[%u, %u), ct::[%u, %u)\n", 
                        __func__, rid, aln->qs, aln->qe, aln->ts, aln->te, aln->sec, tc->c_wsid, tc->c_weid,
                        tc->c_qs, tc->c_qe, tc->c_ts, tc->c_te);
            fprintf(stderr, "[M::%s::] aln->sec::%u, err::%ld\n", __func__, aln->sec, err);  
        }
        assert(err == (int64_t)aln->sec);  
    // }   
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movsd %xmm0, 0x8(%rsp)
movq %r9, %r15
movq %r8, %r13
movq %rcx, %rbp
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, 0x28(%rsp)
movl 0x4(%rsi), %eax
movq %rax, 0x30(%rsp)
movl 0x8(%rsi), %ebx
leaq 0x40(%rsp), %rdi
movq $0x7fffffff, (%rdi)     # imm = 0x7FFFFFFF
subq $0x8, %rsp
xorl %eax, %eax
xorl %edx, %edx
movq %r14, %rcx
movq %rbp, %r8
movq %r13, %r9
pushq %rbx
pushq 0x128(%rsp)
pushq 0x128(%rsp)
pushq %rax
pushq %r15
callq 0x80597
addq $0x30, %rsp
movq %rax, 0x38(%rsp)
subq $0x8, %rsp
leaq 0x48(%rsp), %rdi
movq %r12, 0x28(%rsp)
movq %r12, %rsi
xorl %edx, %edx
movq %r14, 0x20(%rsp)
movq %r14, %rcx
movq %rbp, 0x18(%rsp)
movq %rbp, %r8
movq %r13, %rbp
movq %r13, %r9
movsd 0x10(%rsp), %xmm0
pushq %rbx
pushq 0x128(%rsp)
pushq 0x128(%rsp)
xorl %eax, %eax
pushq %rax
pushq %r15
callq 0x80597
addq $0x30, %rsp
cmpq 0x38(%rsp), %rax
jne 0x8108c
movq $0x7fffffff, 0x40(%rsp) # imm = 0x7FFFFFFF
movq 0x30(%rsp), %r13
cmpl %r13d, %ebx
jae 0x80ed9
xorl %r14d, %r14d
jmp 0x80f3c
xorl %r12d, %r12d
subq $0x8, %rsp
leaq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rsi
xorl %edx, %edx
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %r8
movq %rbp, %r9
movsd 0x10(%rsp), %xmm0
pushq %rbx
pushq 0x128(%rsp)
pushq 0x128(%rsp)
pushq $0x0
pushq %r15
callq 0x80597
addq $0x30, %rsp
testq %rax, %rax
js 0x8106d
movq %rax, %r14
cmpq %r12, %rax
jl 0x8106d
addq $-0x8, %rbx
movq %r14, %r12
cmpq %r13, %rbx
jge 0x80edc
subq $0x8, %rsp
leaq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rbx
movq %rbx, %rsi
xorl %edx, %edx
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %r8
movq %rbp, %r9
movsd 0x10(%rsp), %xmm0
pushq %r13
pushq 0x128(%rsp)
pushq 0x128(%rsp)
pushq $0x0
pushq %r15
callq 0x80597
addq $0x30, %rsp
testq %rax, %rax
js 0x810ab
movq %rax, %r12
cmpq %r14, %rax
jl 0x810ab
movl 0x18(%rbx), %r10d
andl $0x3fffffff, %r10d      # imm = 0x3FFFFFFF
cmpq %r10, %r12
jne 0x80fc7
movl 0x18(%rbx), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
cmpq %rax, %r12
jne 0x810ca
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x209012(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
movl 0x4(%rbx), %r8d
movl 0x8(%rbx), %r9d
movl 0x10(%rbx), %eax
movq %rax, 0x8(%rsp)
movl 0x14(%rbx), %eax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
movl 0x10(%rax), %r13d
movl 0x14(%rax), %ebp
movl (%rax), %ebx
movl 0x4(%rax), %r14d
movl 0x8(%rax), %r11d
movl 0xc(%rax), %r15d
subq $0x8, %rsp
leaq 0x1a82d2(%rip), %rsi    # 0x2292e0
leaq 0x1a832d(%rip), %rdx    # 0x229342
movq 0x30(%rsp), %rcx
xorl %eax, %eax
pushq %r15
pushq %r11
pushq %r14
pushq %rbx
movq 0x48(%rsp), %rbx
pushq %rbp
pushq %r13
pushq %r10
pushq 0x50(%rsp)
pushq 0x50(%rsp)
callq 0x22b0
addq $0x50, %rsp
movq 0x208f9b(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
movl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
andl 0x18(%rbx), %ecx
leaq 0x1a8304(%rip), %rsi    # 0x22935b
leaq 0x1a82e4(%rip), %rdx    # 0x229342
movq %r12, %r8
xorl %eax, %eax
callq 0x22b0
jmp 0x80fa4
leaq 0x1a8254(%rip), %rdi    # 0x2292c8
leaq 0x1a45c8(%rip), %rsi    # 0x225643
leaq 0x1a81ba(%rip), %rcx    # 0x22923c
movl $0x5f43, %edx           # imm = 0x5F43
callq 0x2110
leaq 0x1a819d(%rip), %rdi    # 0x229230
leaq 0x1a45a9(%rip), %rsi    # 0x225643
leaq 0x1a819b(%rip), %rcx    # 0x22923c
movl $0x5f39, %edx           # imm = 0x5F39
callq 0x2110
leaq 0x1a8216(%rip), %rdi    # 0x2292c8
leaq 0x1a458a(%rip), %rsi    # 0x225643
leaq 0x1a817c(%rip), %rcx    # 0x22923c
movl $0x5f50, %edx           # imm = 0x5F50
callq 0x2110
leaq 0x1a82ac(%rip), %rdi    # 0x22937d
leaq 0x1a456b(%rip), %rsi    # 0x225643
leaq 0x1a815d(%rip), %rcx    # 0x22923c
movl $0x5f57, %edx           # imm = 0x5F57
callq 0x2110