// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/ecovlp.cpp
// Function: update_scb(All_reads*, asg16_v*, asg16_v*, asg16_v*, UC_Read*, UC_Read*, asg64_v*, bit_extz_t*, unsigned long)
void update_scb(All_reads *R_INF, asg16_v *scc, asg16_v *scb, asg16_v *scb_res, UC_Read *qu, UC_Read *tu, asg64_v *srt, bit_extz_t *exz, uint64_t rid)
{
    char *qstr = NULL, *tstr = NULL; uint64_t ql = 0, tl = 0;
    uint64_t ck, qk, tk, k, wq[2], wt[2]; uint32_t len; uint16_t c, bq, bt;
    gen_ori_seq0(qu->seq, qu->length, tu, scb, rid); ///tstr = tu->seq; tl = tu->length;

    ck = qk = tk = 0; ql = qu->length;
    while (ck < scc->n) {
        wq[0] = qk; wt[0] = tk;
        ck = pop_trace_bp_f(scc, ck, &c, &bq, &bt, &len);
        if(c != 2) qk += len;
        if(c != 3) tk += len;
        wq[1] = qk; wt[1] = tk;
    }
    assert(qk == ql);
    tl = tk; resize_UC_Read(qu, ql + tl);
    qstr = qu->seq; tstr = qu->seq + ql;

    ck = 0; qk = tk = 0; 
    while (ck < scc->n) {
        wq[0] = qk; wt[0] = tk;
        ck = pop_trace_bp_f(scc, ck, &c, &bq, &bt, &len);
        if(c != 2) qk += len;
        if(c != 3) tk += len;
        wq[1] = qk; wt[1] = tk;
        // if(xk > (uint32_t)p->z.length) fprintf(stderr, "[M::%s] xk::%u, len::%u, c::%u, rid::%ld\n", __func__, xk, (uint32_t)p->z.length, c, i);
        if(c == 0) {
            memcpy(tstr + wt[0], qstr + wq[0], (wq[1]-wq[0])*sizeof((*qstr)));
        } else if(c == 1 || c == 2) {
            for (k = wt[0]; k < wt[1]; k++) tstr[k] = s_H[bt]; 
        }
        // if(i == 700) fprintf(stderr, "|%u%c(%c)(x::%u)(y::%u)", len, cm[c], ((c==1)||(c==2))?(cc[b]):('*'), wx[1], wy[1]); // s_H
    }

    qstr = tstr; ql = tl;
    tstr = tu->seq; tl = tu->length;

    // fprintf(stderr, "\n[M::%s] ql::%lu, tl::%lu, rid::%lu\n", __func__, ql, tl, rid);

    gen_updated_trace(scc, scb, scb_res, qstr, ql, tstr, tl, srt, exz, rid);

    

    ///debug
    // resize_UC_Read(tu, ql + tl);
    // memcpy(tu->seq + tl, qstr, ql); tstr = tu->seq; qstr = tu->seq + tl;

    // resize_UC_Read(qu, ql + tl);
    // memcpy(qu->seq, tu->seq, ql + tl); tstr = qu->seq; qstr = qu->seq + tl;

    // gen_ori_seq0(qstr, ql, tu, scb_res, rid);
    // assert(memcmp(tstr, tu->seq, tl) == 0);
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, %rbx
movq %rcx, 0x38(%rsp)
movq %rdx, %rcx
movq %rsi, %r15
movq 0x90(%rsp), %r8
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
movq %r9, 0x40(%rsp)
movq %r9, %rdx
movq %rcx, 0x30(%rsp)
callq 0x14a720
movq %rbx, 0x18(%rsp)
movq 0x8(%rbx), %r13
xorl %r12d, %r12d
leaq 0x10(%rsp), %r14
xorl %esi, %esi
xorl %ebp, %ebp
xorl %ebx, %ebx
cmpq (%r15), %rsi
jae 0x14b672
movq %r15, %rdi
leaq 0xc(%rsp), %rdx
leaq 0x16(%rsp), %rcx
leaq 0xe(%rsp), %r8
movq %r14, %r9
callq 0xeeaa9
movl %eax, %esi
movzwl 0xc(%rsp), %eax
cmpw $0x2, %ax
movl 0x10(%rsp), %ecx
movq %rcx, %rdx
cmoveq %r12, %rdx
addq %rdx, %rbp
cmpw $0x3, %ax
cmoveq %r12, %rcx
addq %rcx, %rbx
jmp 0x14b62d
movq %r15, 0x20(%rsp)
cmpq %r13, %rbp
jne 0x14b79d
movq %rbx, 0x28(%rsp)
leaq (%rbx,%r13), %rsi
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x562fa
movq (%rbx), %rax
movq %rax, 0x18(%rsp)
addq %rax, %r13
leaq 0x108088(%rip), %rbp    # 0x253730
xorl %eax, %eax
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x20(%rsp), %rdi
movl %eax, %ecx
cmpq %rcx, (%rdi)
jbe 0x14b75a
movq %r12, %rbx
movl %eax, %esi
leaq 0xc(%rsp), %rdx
leaq 0x16(%rsp), %rcx
leaq 0xe(%rsp), %r8
leaq 0x10(%rsp), %r9
callq 0xeeaa9
movzwl 0xc(%rsp), %ecx
cmpw $0x2, %cx
movl 0x10(%rsp), %edx
movq %rdx, %r14
movl $0x0, %esi
cmoveq %rsi, %r14
addq %r15, %r14
cmpw $0x3, %cx
movq %rdx, %r12
cmoveq %rsi, %r12
addq %rbx, %r12
testw %cx, %cx
je 0x14b73b
movq %r14, %r15
cmpw $0x2, %cx
movq 0x20(%rsp), %rdi
ja 0x14b6b5
jmp 0x14b72e
movzwl 0xe(%rsp), %ecx
movb (%rbp,%rcx), %cl
movb %cl, (%r13,%rbx)
incq %rbx
cmpq %r12, %rbx
jb 0x14b71d
movq %r14, %r15
jmp 0x14b6b5
addq %r13, %rbx
addq 0x18(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
movl %eax, %ebx
callq 0x2160
movl %ebx, %eax
movq %r14, %r15
jmp 0x14b6b0
movq 0x40(%rsp), %rax
movq (%rax), %r9
subq $0x8, %rsp
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq %r13, %rcx
movq 0x30(%rsp), %r8
pushq 0x90(%rsp)
pushq 0x90(%rsp)
pushq 0x8(%rax)
callq 0x14aebb
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa5b67(%rip), %rdi     # 0x1f130b
leaq 0xa4750(%rip), %rsi     # 0x1efefb
leaq 0xa5b62(%rip), %rcx     # 0x1f1314
movl $0x163f, %edx           # imm = 0x163F
callq 0x2110