// File: 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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
jbe 0x60ad1
movq -0x8(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x8(%rbp), %rcx
addl 0x1c(%rcx), %eax
movl %eax, %eax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jne 0x6086e
jmp 0x6088d
leaq 0x322f43(%rip), %rdi    # 0x3837b8
leaq 0x321a9f(%rip), %rsi    # 0x38231b
movl $0x3e5c, %edx           # imm = 0x3E5C
leaq 0x322f50(%rip), %rcx    # 0x3837d8
callq 0x2130
movq -0x18(%rbp), %rax
cmpq $0x0, 0xa8(%rax)
jbe 0x60acf
movl $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
subq $0x1, %rcx
movzwl (%rax,%rcx,2), %eax
sarl $0xe, %eax
movw %ax, -0x1a(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
subq $0x1, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
addq $0xa8, %rdi
movl -0x28(%rbp), %esi
leaq -0x1c(%rbp), %rdx
leaq -0x24(%rbp), %rcx
callq 0xa1ee0
movl %eax, -0x28(%rbp)
movzwl -0x1a(%rbp), %eax
movzwl -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jne 0x60935
movl -0x20(%rbp), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x1c(%rax)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movw -0x1c(%rbp), %ax
movl -0x24(%rbp), %edx
movzwl %ax, %esi
callq 0xc1070
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x18(%rcx), %ecx
subq %rcx, %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x18(%rbp), %rax
movq 0xa8(%rax), %rax
movl -0x28(%rbp), %ecx
subq %rcx, %rax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jbe 0x60acd
jmp 0x60987
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x2c(%rbp), %edx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x60a76
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movl -0x2c(%rbp), %eax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
shrq %rcx
movq -0x10(%rbp), %rax
orq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
shrq $0x2, %rcx
movq -0x10(%rbp), %rax
orq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
shrq $0x4, %rcx
movq -0x10(%rbp), %rax
orq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
shrq $0x8, %rcx
movq -0x10(%rbp), %rax
orq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
shrq $0x10, %rcx
movq -0x10(%rbp), %rax
orq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
shlq %rsi
callq 0x2360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
jmp 0x60a78
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
shlq %rax
addq %rax, %rdi
movq -0x18(%rbp), %rax
movq 0xb8(%rax), %rsi
movl -0x28(%rbp), %eax
shlq %rax
addq %rax, %rsi
movl -0x2c(%rbp), %eax
movl %eax, %edx
shlq %rdx
callq 0x2180
movl -0x2c(%rbp), %ecx
movq -0x8(%rbp), %rax
addl 0x1c(%rax), %ecx
movl %ecx, 0x1c(%rax)
movl -0x2c(%rbp), %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
jmp 0x60acf
jmp 0x60ae2
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x38180
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)