// File: /workspace/github_cpp_makefile_star2_O2/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 $0xc8, %rsp
movsd %xmm0, (%rsp)
movq %r9, 0x10(%rsp)
movq %r8, %rbx
movq %rcx, %r13
movq %rdx, %rbp
movq %rsi, %r14
movq %rdi, 0x20(%rsp)
movq 0x108(%rsp), %rdx
movq 0x100(%rsp), %rcx
movl 0x4(%rsi), %eax
movq %rax, 0x8(%rsp)
movl 0x8(%rsi), %r15d
leaq 0x30(%rsp), %r12
movq $0x7fffffff, (%r12)     # imm = 0x7FFFFFFF
subq $0x30, %rsp
movq %r15, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
andq $0x0, 0x8(%rsp)
movq %r9, (%rsp)
movq %r12, %rdi
xorl %edx, %edx
movq %rbp, %rcx
movq %r13, %r8
movq %rbx, %r9
callq 0x4cafd
addq $0x30, %rsp
movq %rax, 0x28(%rsp)
subq $0x8, %rsp
movq %r12, %rdi
movq %r14, %r12
movq %r14, %rsi
xorl %edx, %edx
movq %rbp, 0x20(%rsp)
movq %rbp, %rcx
movq %r13, %rbp
movq %r13, %r8
movq %rbx, %r13
movq %rbx, %r9
movsd 0x8(%rsp), %xmm0
pushq %r15
pushq 0x118(%rsp)
pushq 0x118(%rsp)
pushq $0x0
movq 0x38(%rsp), %rax
movq %rax, %rbx
pushq %rax
callq 0x4cafd
addq $0x30, %rsp
cmpq 0x28(%rsp), %rax
jne 0x4d6ad
leaq 0x30(%rsp), %rax
movq $0x7fffffff, (%rax)     # imm = 0x7FFFFFFF
xorl %r14d, %r14d
cmpq 0x8(%rsp), %r15
jl 0x4d55f
subq $0x8, %rsp
leaq 0x38(%rsp), %rdi
movq %r12, %rsi
xorl %edx, %edx
movq 0x20(%rsp), %rcx
movq %rbp, %r8
movq %r13, %r9
movsd 0x8(%rsp), %xmm0
pushq %r15
pushq 0x118(%rsp)
pushq 0x118(%rsp)
pushq $0x0
pushq %rbx
callq 0x4cafd
addq $0x30, %rsp
testq %rax, %rax
js 0x4d540
addq $-0x8, %r15
cmpq %r14, %rax
movq %rax, %r14
jge 0x4d4ed
leaq 0x199de1(%rip), %rdi    # 0x1e7328
leaq 0x196155(%rip), %rsi    # 0x1e36a3
leaq 0x199d47(%rip), %rcx    # 0x1e729c
movl $0x5f43, %edx           # imm = 0x5F43
callq 0x2110
subq $0x30, %rsp
movq 0x38(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x138(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x130(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %rbx, (%rsp)
andq $0x0, 0x8(%rsp)
leaq 0x60(%rsp), %rdi
movq %r12, %rbx
movq %r12, %rsi
xorl %edx, %edx
movq 0x48(%rsp), %rcx
movq %rbp, %r8
movq %r13, %r9
movsd 0x30(%rsp), %xmm0
callq 0x4cafd
addq $0x30, %rsp
testq %rax, %rax
js 0x4d6cc
movq %rax, %r12
cmpq %r14, %rax
jl 0x4d6cc
movl 0x18(%rbx), %r10d
andl $0x3fffffff, %r10d      # imm = 0x3FFFFFFF
cmpq %r10, %r12
jne 0x4d5f8
cmpq %r10, %r12
jne 0x4d6eb
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2059e1(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
movl 0x4(%rbx), %r8d
movl 0x8(%rbx), %r9d
movl 0x10(%rbx), %eax
movq %rax, (%rsp)
movl 0x14(%rbx), %eax
movq %rax, 0x8(%rsp)
movq 0x18(%rsp), %rax
movl 0x10(%rax), %ecx
movq %rcx, 0x10(%rsp)
movl 0x14(%rax), %ebp
movq %rbx, %r13
movl (%rax), %ebx
movl 0x4(%rax), %r15d
movl 0x8(%rax), %r11d
movl 0xc(%rax), %r14d
subq $0x8, %rsp
leaq 0x199cfb(%rip), %rsi    # 0x1e7340
leaq 0x199d56(%rip), %rdx    # 0x1e73a2
movq 0x28(%rsp), %rcx
xorl %eax, %eax
pushq %r14
pushq %r11
pushq %r15
pushq %rbx
pushq %rbp
pushq 0x40(%rsp)
pushq %r10
pushq 0x48(%rsp)
pushq 0x48(%rsp)
callq 0x22b0
addq $0x50, %rsp
movq 0x205967(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
movl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
andl 0x18(%r13), %ecx
leaq 0x199d2f(%rip), %rsi    # 0x1e73bb
leaq 0x199d0f(%rip), %rdx    # 0x1e73a2
movq %r12, %r8
xorl %eax, %eax
callq 0x22b0
movl 0x18(%r13), %r10d
andl $0x3fffffff, %r10d      # imm = 0x3FFFFFFF
jmp 0x4d5dd
leaq 0x199bdc(%rip), %rdi    # 0x1e7290
leaq 0x195fe8(%rip), %rsi    # 0x1e36a3
leaq 0x199bda(%rip), %rcx    # 0x1e729c
movl $0x5f39, %edx           # imm = 0x5F39
callq 0x2110
leaq 0x199c55(%rip), %rdi    # 0x1e7328
leaq 0x195fc9(%rip), %rsi    # 0x1e36a3
leaq 0x199bbb(%rip), %rcx    # 0x1e729c
movl $0x5f50, %edx           # imm = 0x5F50
callq 0x2110
leaq 0x199ceb(%rip), %rdi    # 0x1e73dd
leaq 0x195faa(%rip), %rsi    # 0x1e36a3
leaq 0x199b9c(%rip), %rcx    # 0x1e729c
movl $0x5f57, %edx           # imm = 0x5F57
callq 0x2110