// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movq %rcx, -0x48(%rbp)
movq %r8, -0x50(%rbp)
movq %r9, -0x58(%rbp)
movsd %xmm0, -0x60(%rbp)
movq -0x38(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0x78(%rbp)
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x68(%rbp)
movq $0x7fffffff, -0x120(%rbp) # imm = 0x7FFFFFFF
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
movq -0x50(%rbp), %r9
movq -0x58(%rbp), %rbx
movq 0x10(%rbp), %r11
movq 0x18(%rbp), %r10
movsd -0x60(%rbp), %xmm0
movq -0x68(%rbp), %rax
leaq -0x120(%rbp), %rdi
xorl %edx, %edx
movq %rbx, (%rsp)
movq $0x0, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x93360
movq %rax, -0x88(%rbp)
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
movq -0x50(%rbp), %r9
movq -0x58(%rbp), %rbx
movq 0x10(%rbp), %r11
movq 0x18(%rbp), %r10
movsd -0x60(%rbp), %xmm0
movq -0x68(%rbp), %rax
leaq -0x120(%rbp), %rdi
xorl %edx, %edx
movq %rbx, (%rsp)
movq $0x0, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x93360
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x88(%rbp), %rax
jne 0x9498a
jmp 0x949a9
leaq 0x2f1577(%rip), %rdi    # 0x385f08
leaq 0x2ed983(%rip), %rsi    # 0x38231b
movl $0x5f39, %edx           # imm = 0x5F39
leaq 0x2f1570(%rip), %rcx    # 0x385f14
callq 0x2130
movq -0x80(%rbp), %rax
movq %rax, -0x68(%rbp)
movq $0x7fffffff, -0x120(%rbp) # imm = 0x7FFFFFFF
movq $0x0, -0x88(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x78(%rbp), %rax
jl 0x94a94
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
movq -0x50(%rbp), %r9
movq -0x58(%rbp), %rbx
movq 0x10(%rbp), %r11
movq 0x18(%rbp), %r10
movsd -0x60(%rbp), %xmm0
movq -0x68(%rbp), %rax
leaq -0x120(%rbp), %rdi
xorl %edx, %edx
movq %rbx, (%rsp)
movq $0x0, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x93360
movq %rax, -0x70(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x70(%rbp)
movb %al, -0x121(%rbp)
jl 0x94a4b
movq -0x70(%rbp), %rax
cmpq -0x88(%rbp), %rax
setge %al
movb %al, -0x121(%rbp)
movb -0x121(%rbp), %al
testb $0x1, %al
jne 0x94a57
jmp 0x94a59
jmp 0x94a78
leaq 0x2f1540(%rip), %rdi    # 0x385fa0
leaq 0x2ed8b4(%rip), %rsi    # 0x38231b
movl $0x5f43, %edx           # imm = 0x5F43
leaq 0x2f14a1(%rip), %rcx    # 0x385f14
callq 0x2130
movq -0x70(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x68(%rbp), %rax
subq $0x8, %rax
movq %rax, -0x68(%rbp)
jmp 0x949c7
movq -0x78(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
movq -0x50(%rbp), %r9
movq -0x58(%rbp), %rbx
movq 0x10(%rbp), %r11
movq 0x18(%rbp), %r10
movsd -0x60(%rbp), %xmm0
movq -0x68(%rbp), %rax
leaq -0x120(%rbp), %rdi
xorl %edx, %edx
movq %rbx, (%rsp)
movq $0x0, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x93360
movq %rax, -0x70(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x70(%rbp)
movb %al, -0x122(%rbp)
jl 0x94b12
movq -0x70(%rbp), %rax
cmpq -0x88(%rbp), %rax
setge %al
movb %al, -0x122(%rbp)
movb -0x122(%rbp), %al
testb $0x1, %al
jne 0x94b1e
jmp 0x94b20
jmp 0x94b3f
leaq 0x2f1479(%rip), %rdi    # 0x385fa0
leaq 0x2ed7ed(%rip), %rsi    # 0x38231b
movl $0x5f50, %edx           # imm = 0x5F50
leaq 0x2f13da(%rip), %rcx    # 0x385f14
callq 0x2130
movq -0x70(%rbp), %rax
movq -0x38(%rbp), %rcx
movl 0x18(%rcx), %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
je 0x94c3e
movq 0x32f47e(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
movl 0x4(%rax), %r8d
movq -0x38(%rbp), %rax
movl 0x8(%rax), %r9d
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x38(%rbp), %rdx
movl 0x14(%rdx), %r13d
movq -0x38(%rbp), %rdx
movl 0x18(%rdx), %r12d
andl $0x3fffffff, %r12d      # imm = 0x3FFFFFFF
movq -0x40(%rbp), %rdx
movl 0x10(%rdx), %r15d
movq -0x40(%rbp), %rdx
movl 0x14(%rdx), %r14d
movq -0x40(%rbp), %rdx
movl (%rdx), %ebx
movq -0x40(%rbp), %rdx
movl 0x4(%rdx), %r11d
movq -0x40(%rbp), %rdx
movl 0x8(%rdx), %r10d
movq -0x40(%rbp), %rdx
movl 0xc(%rdx), %edx
movl %edx, -0x128(%rbp)
leaq 0x2f13e7(%rip), %rsi    # 0x385fb8
leaq 0x2f1442(%rip), %rdx    # 0x38601a
movl %eax, (%rsp)
movl -0x128(%rbp), %eax
movl %r13d, 0x8(%rsp)
movl %r12d, 0x10(%rsp)
movl %r15d, 0x18(%rsp)
movl %r14d, 0x20(%rsp)
movl %ebx, 0x28(%rsp)
movl %r11d, 0x30(%rsp)
movl %r10d, 0x38(%rsp)
movl %eax, 0x40(%rsp)
movb $0x0, %al
callq 0x22a0
movq 0x32f3cb(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movq -0x70(%rbp), %r8
leaq 0x2f1403(%rip), %rsi    # 0x386033
leaq 0x2f13e3(%rip), %rdx    # 0x38601a
movb $0x0, %al
callq 0x22a0
movq -0x70(%rbp), %rax
movq -0x38(%rbp), %rcx
movl 0x18(%rcx), %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jne 0x94c58
jmp 0x94c77
leaq 0x2f13f6(%rip), %rdi    # 0x386055
leaq 0x2ed6b5(%rip), %rsi    # 0x38231b
movl $0x5f57, %edx           # imm = 0x5F57
leaq 0x2f12a2(%rip), %rcx    # 0x385f14
callq 0x2130
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)