// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %rsp
movq %r8, %r14
movq %rcx, 0x20(%rsp)
movq %rdx, %rcx
movq %rsi, %rbx
movq 0x80(%rsp), %r8
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq %r9, 0x28(%rsp)
movq %r9, %rdx
movq %rcx, 0x18(%rsp)
callq 0x18810d
movq 0x8(%r14), %rax
movq %rax, (%rsp)
movq (%rbx), %rax
testq %rax, %rax
movq %rbx, 0x8(%rsp)
je 0x1896eb
movq 0x10(%rbx), %rdx
xorl %esi, %esi
xorl %r13d, %r13d
xorl %ecx, %ecx
xorl %edi, %edi
movzwl (%rdx,%rdi,2), %r11d
movl %r11d, %r8d
shrl $0xe, %r8d
leal -0x2(%r8), %r9d
cmpl $0x2, %r9d
jae 0x18960d
movl %r11d, %r9d
shrl $0xc, %r9d
andl $0x3, %r9d
andl $0xfff, %r11d           # imm = 0xFFF
jmp 0x18961e
testl %r8d, %r8d
jne 0x189626
andl $0x3fff, %r11d          # imm = 0x3FFF
movw $0xffff, %r9w           # imm = 0xFFFF
movl $0xffff, %r10d          # imm = 0xFFFF
jmp 0x189643
movl %r11d, %r9d
shrl $0xc, %r9d
andl $0x3, %r9d
movl %r11d, %r10d
shrl $0xa, %r10d
andl $0x3, %r10d
andl $0x3ff, %r11d           # imm = 0x3FF
movzwl %r11w, %r11d
incl %edi
cmpq %rdi, %rax
jbe 0x1896c0
movzwl (%rdx,%rdi,2), %ebx
movl %ebx, %ebp
shrl $0xe, %ebp
cmpl %r8d, %ebp
jne 0x1896c0
movzwl %r8w, %r15d
leal -0x2(%r15), %ebp
cmpl $0x2, %ebp
jae 0x18967c
movl %ebx, %r15d
shrl $0xc, %r15d
andl $0x3, %r15d
andl $0xfff, %ebx            # imm = 0xFFF
jmp 0x18968c
testl %r15d, %r15d
jne 0x189694
andl $0x3fff, %ebx           # imm = 0x3FFF
movw $0xffff, %r15w          # imm = 0xFFFF
movl $0xffff, %r12d          # imm = 0xFFFF
jmp 0x1896b0
movl %ebx, %r15d
shrl $0xc, %r15d
andl $0x3, %r15d
movl %ebx, %r12d
shrl $0xa, %r12d
andl $0x3, %r12d
andl $0x3ff, %ebx            # imm = 0x3FF
cmpl %r10d, %r12d
jne 0x1896c0
cmpw %r15w, %r9w
jne 0x1896c0
addl %ebx, %r11d
jmp 0x189647
cmpw $0x2, %r8w
movl %r11d, %r9d
movq %r9, %r10
cmoveq %rsi, %r10
addq %r10, %rcx
cmpw $0x3, %r8w
movl %edi, %edi
cmoveq %rsi, %r9
addq %r9, %r13
cmpq %rdi, %rax
ja 0x1895e3
jmp 0x1896f0
xorl %ecx, %ecx
xorl %r13d, %r13d
movq (%rsp), %rax
cmpq %rax, %rcx
jne 0x189907
movq %rax, %rcx
movq %r13, 0x10(%rsp)
leaq (%rax,%r13), %r15
cmpq %r15, 0x10(%r14)
jge 0x189725
movq (%r14), %rdi
movq %r15, %rsi
callq 0x2370
movq (%rsp), %rcx
movq %rax, (%r14)
movq %r15, 0x10(%r14)
movq (%r14), %rax
movq %rax, 0x30(%rsp)
addq %rax, %rcx
movq %rcx, (%rsp)
movq 0x8(%rsp), %rcx
movq (%rcx), %rdx
testq %rdx, %rdx
je 0x1898bf
xorl %r12d, %r12d
leaq 0x100fe1(%rip), %r13    # 0x28a730
xorl %r15d, %r15d
xorl %ebx, %ebx
movq %r12, %rdi
movq 0x10(%rcx), %r8
movzwl (%r8,%rbx,2), %ecx
movl %ecx, %eax
shrl $0xe, %eax
leal -0x2(%rax), %esi
cmpl $0x2, %esi
jae 0x189781
movl %ecx, %esi
shrl $0xc, %esi
andl $0x3, %esi
movl %ecx, %r10d
andl $0xfff, %r10d           # imm = 0xFFF
jmp 0x189793
testl %eax, %eax
jne 0x18979b
movl %ecx, %r10d
andl $0x3fff, %r10d          # imm = 0x3FFF
movw $0xffff, %si            # imm = 0xFFFF
movl $0xffff, %r9d           # imm = 0xFFFF
jmp 0x1897b8
movl %ecx, %esi
shrl $0xc, %esi
andl $0x3, %esi
movl %ecx, %r9d
shrl $0xa, %r9d
andl $0x3, %r9d
movl %ecx, %r10d
andl $0x3ff, %r10d           # imm = 0x3FF
movzwl %r10w, %r10d
incl %ebx
cmpq %rbx, %rdx
jbe 0x18983b
movzwl %ax, %r11d
movzwl (%r8,%rbx,2), %r14d
movl %r14d, %ebp
shrl $0xe, %ebp
cmpl %eax, %ebp
jne 0x18983b
leal -0x2(%r11), %ebp
cmpl $0x2, %ebp
jae 0x1897f3
movl %r14d, %r12d
shrl $0xc, %r12d
andl $0x3, %r12d
andl $0xfff, %r14d           # imm = 0xFFF
jmp 0x189804
testl %r11d, %r11d
jne 0x18980b
andl $0x3fff, %r14d          # imm = 0x3FFF
movw $0xffff, %r12w          # imm = 0xFFFF
movl $0xffff, %ebp           # imm = 0xFFFF
jmp 0x189826
movl %r14d, %r12d
shrl $0xc, %r12d
andl $0x3, %r12d
movl %r14d, %ebp
shrl $0xa, %ebp
andl $0x3, %ebp
andl $0x3ff, %r14d           # imm = 0x3FF
cmpl %r9d, %ebp
jne 0x18983b
cmpw %r12w, %si
jne 0x18983b
addl %r14d, %r10d
incl %ebx
cmpq %rbx, %rdx
ja 0x1897c7
cmpw $0x2, %ax
movl %r10d, %edx
movq %rdx, %r14
movl $0x0, %r8d
cmoveq %r8, %r14
cmpw $0x3, %ax
movl $0xffff, %r9d           # imm = 0xFFFF
cmovel %r9d, %esi
cmoveq %r8, %rdx
leaq (%rdx,%rdi), %r12
cmpl $0x3fff, %ecx           # imm = 0x3FFF
ja 0x189884
addq (%rsp), %rdi
movq 0x30(%rsp), %rax
leaq (%rax,%r15), %rsi
movq %r14, %rdx
callq 0x2160
jmp 0x1898a9
cmpw $0x3, %ax
je 0x1898a9
cmpq %r12, %rdi
jae 0x1898a9
movzwl %si, %eax
addq (%rsp), %rdi
xorl %ecx, %ecx
movb (%r13,%rax), %sil
movb %sil, (%rdi,%rcx)
incq %rcx
cmpq %rcx, %rdx
jne 0x189898
addq %r14, %r15
movl %ebx, %ebx
movq 0x8(%rsp), %rcx
movq (%rcx), %rdx
cmpq %rbx, %rdx
ja 0x189754
movq 0x28(%rsp), %rax
movq (%rax), %r9
subq $0x8, %rsp
movq %rcx, %rdi
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x8(%rsp), %rcx
movq 0x18(%rsp), %r8
pushq 0x80(%rsp)
pushq 0x80(%rsp)
pushq 0x8(%rax)
callq 0x188b30
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa98ed(%rip), %rdi     # 0x2331fb
leaq 0xa84d6(%rip), %rsi     # 0x231deb
leaq 0xa98e8(%rip), %rcx     # 0x233204
movl $0x163f, %edx           # imm = 0x163F
callq 0x2110