// File: 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
movq %rsp, %rbp
pushq %rbx
subq $0xc8, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x38(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq 0x20(%rbp), %r8
callq 0x2645a0
movq $0x0, -0x70(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x60(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x26610b
movq -0x68(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x18(%rbp), %rdi
movq -0x60(%rbp), %rax
movl %eax, %esi
leaq -0xa6(%rbp), %rdx
leaq -0xa8(%rbp), %rcx
leaq -0xaa(%rbp), %r8
leaq -0xa4(%rbp), %r9
callq 0x1b53f0
movl %eax, %eax
movq %rax, -0x60(%rbp)
movzwl -0xa6(%rbp), %eax
cmpl $0x2, %eax
je 0x2660d6
movl -0xa4(%rbp), %eax
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
movzwl -0xa6(%rbp), %eax
cmpl $0x3, %eax
je 0x2660f0
movl -0xa4(%rbp), %eax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x266064
movq -0x68(%rbp), %rax
cmpq -0x50(%rbp), %rax
jne 0x266117
jmp 0x266136
leaq 0x129f0c(%rip), %rdi    # 0x39002a
leaq 0x128ae6(%rip), %rsi    # 0x38ec0b
movl $0x163f, %edx           # imm = 0x163F
leaq 0x129f02(%rip), %rcx    # 0x390033
callq 0x2130
movq -0x70(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rdi
movq -0x50(%rbp), %rsi
addq -0x58(%rbp), %rsi
callq 0xa62c0
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x60(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x2662c3
movq -0x68(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x18(%rbp), %rdi
movq -0x60(%rbp), %rax
movl %eax, %esi
leaq -0xa6(%rbp), %rdx
leaq -0xa8(%rbp), %rcx
leaq -0xaa(%rbp), %r8
leaq -0xa4(%rbp), %r9
callq 0x1b53f0
movl %eax, %eax
movq %rax, -0x60(%rbp)
movzwl -0xa6(%rbp), %eax
cmpl $0x2, %eax
je 0x2661f3
movl -0xa4(%rbp), %eax
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
movzwl -0xa6(%rbp), %eax
cmpl $0x3, %eax
je 0x26620d
movl -0xa4(%rbp), %eax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x98(%rbp)
movzwl -0xa6(%rbp), %eax
cmpl $0x0, %eax
jne 0x26625e
movq -0x48(%rbp), %rdi
addq -0xa0(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
subq -0x90(%rbp), %rdx
shlq $0x0, %rdx
callq 0x2180
jmp 0x2662be
movzwl -0xa6(%rbp), %eax
cmpl $0x1, %eax
je 0x266276
movzwl -0xa6(%rbp), %eax
cmpl $0x2, %eax
jne 0x2662bc
movq -0xa0(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x98(%rbp), %rax
jae 0x2662ba
movzwl -0xaa(%rbp), %eax
movl %eax, %ecx
leaq 0x15e4b2(%rip), %rax    # 0x3c4750
movb (%rax,%rcx), %dl
movq -0x48(%rbp), %rax
movq -0x78(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x266281
jmp 0x2662bc
jmp 0x2662be
jmp 0x266181
movq -0x48(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x50(%rbp), %r8
movq -0x48(%rbp), %r9
movq -0x58(%rbp), %rbx
movq 0x10(%rbp), %r11
movq 0x18(%rbp), %r10
movq 0x20(%rbp), %rax
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x265100
addq $0xc8, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)