// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: append_wcigar(window_list*, window_list_alloc*, bit_extz_t*)
void append_wcigar(window_list *idx, window_list_alloc *res, bit_extz_t *exz)
{
    // fprintf(stderr, "[M::%s::] idx->cidx::%u, idx->clen::%u, res->c.n_0::%u, exz->cigar.n::%u, ", 
    //         __func__, idx->cidx, idx->clen, (uint32_t)res->c.n, (uint32_t)exz->cigar.n);
    if(idx->clen > 0) {
        // if(!(idx->cidx+idx->clen == res->c.n)) {
        //     fprintf(stderr, "[M::%s::] idx->cidx::%u, idx->clen::%u, res->c.n::%u\n", 
        //     __func__, idx->cidx, idx->clen, (uint32_t)res->c.n);
        // }
        assert(idx->cidx+idx->clen == res->c.n);
        if(exz->cigar.n > 0) {
            uint16_t c0, c; uint32_t l0, l, ci = 0, cn; 
            ///last item of old cigar
            c0 = (res->c.a[res->c.n-1]>>14); l0 = (res->c.a[res->c.n-1]&(0x3fff));
            ///first item of new cigar
            ci = pop_trace(&(exz->cigar), ci, &c, &l);
            if(c0 == c) {l += l0; res->c.n--; idx->clen--;}
            push_trace(((asg16_v *)(&(res->c))), c, l); 
            idx->clen = res->c.n-idx->cidx;

            cn = exz->cigar.n-ci;
            if(cn > 0) {
                kv_resize(uint16_t, res->c, (res->c.n+cn));
                memcpy(res->c.a+res->c.n, exz->cigar.a+ci, cn*sizeof(*(res->c.a)));
                idx->clen += cn; res->c.n += cn;
            }
        }
    } else {
        push_wcigar(idx, res, exz);///if exz is the first item
    }
    // fprintf(stderr, "[M::%s::] res->c.n::%u\n", __func__, (uint32_t)res->c.n);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r12
movq %rdi, %rbx
movl 0x1c(%rdi), %eax
testl %eax, %eax
je 0x3491d
addl 0x18(%rbx), %eax
cmpq %rax, 0x18(%r12)
jne 0x34936
cmpq $0x0, 0xa8(%rdx)
je 0x3490e
leaq 0x18(%r12), %rbp
movq %rdx, 0x18(%rsp)
leaq 0xa8(%rdx), %rdi
movq 0x28(%r12), %rcx
movzwl -0x2(%rcx,%rax,2), %r14d
movl %r14d, %r13d
shrl $0xe, %r13d
leaq 0x16(%rsp), %r15
leaq 0xc(%rsp), %rcx
movq %rdi, 0x20(%rsp)
xorl %esi, %esi
movq %r15, %rdx
callq 0x53a7d
movl %eax, 0x10(%rsp)
movzwl (%r15), %eax
leaq 0xc(%rsp), %rcx
movl (%rcx), %edx
cmpw %ax, %r13w
jne 0x3484d
andl $0x3fff, %r14d          # imm = 0x3FFF
addl %r14d, %edx
movl %edx, 0xc(%rsp)
decq (%rbp)
decl 0x1c(%rbx)
movq %rbp, %r14
movzwl %ax, %esi
movq %rbp, %rdi
callq 0x62885
movq (%rbp), %rcx
movl 0x18(%rbx), %eax
movl %ecx, %edx
subl %eax, %edx
movl %edx, 0x1c(%rbx)
movq 0x20(%rsp), %rax
movl (%rax), %ebp
movl 0x10(%rsp), %eax
subl %eax, %ebp
je 0x3490e
movl %eax, %r13d
movl %ebp, %r15d
leaq (%rcx,%r15), %rdx
movq 0x28(%r12), %rax
cmpq %rdx, 0x20(%r12)
jae 0x348e9
decq %rdx
movq %rdx, %rcx
shrq %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x2, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x8, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x10, %rcx
orq %rdx, %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x20(%r12)
leaq 0x2(,%rcx,2), %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x28(%r12)
movq 0x18(%r12), %rcx
leaq (%rax,%rcx,2), %rdi
addq %r13, %r13
movq 0x18(%rsp), %rax
addq 0xb8(%rax), %r13
leaq (%r15,%r15), %rdx
movq %r13, %rsi
callq 0x2160
addl %ebp, 0x1c(%rbx)
addq %r15, (%r14)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movq %r12, %rsi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1e842
leaq 0x1b0203(%rip), %rdi    # 0x1e4b40
leaq 0x1aed5f(%rip), %rsi    # 0x1e36a3
leaq 0x1b0215(%rip), %rcx    # 0x1e4b60
movl $0x3e5c, %edx           # imm = 0x3E5C
callq 0x2110