// File: /workspace/github_cpp_makefile_star2_O3/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 $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movl 0x1c(%rdi), %ecx
testl %ecx, %ecx
je 0x65927
movl 0x18(%r14), %eax
addl %ecx, %eax
cmpq %rax, 0x18(%rbx)
jne 0x65a52
movq 0xa8(%rdx), %r8
testq %r8, %r8
je 0x65a43
movq 0x28(%rbx), %rdi
movzwl -0x2(%rdi,%rax,2), %r15d
movl %r15d, %esi
shrl $0xe, %esi
movq 0xb8(%rdx), %r10
movzwl (%r10), %r13d
movl %r13d, %r9d
shrl $0xe, %r9d
movl %r13d, 0xc(%rsp)
andl $0x3fff, %r13d          # imm = 0x3FFF
movl $0x1, %r12d
cmpq $0x1, %r8
je 0x658a3
movl $0x1, %r12d
movl $0x1, %r11d
movzwl (%r10,%r11,2), %r11d
movl %r11d, %ebp
shrl $0xe, %ebp
cmpl %r9d, %ebp
jne 0x658a3
andl $0x3fff, %r11d          # imm = 0x3FFF
addl %r11d, %r13d
incl %r12d
movq %r12, %r11
cmpq %r12, %r8
ja 0x6587e
cmpw %r9w, %si
jne 0x658c0
andl $0x3fff, %r15d          # imm = 0x3FFF
addl %r15d, %r13d
decq %rax
movq %rax, 0x18(%rbx)
decl %ecx
movl %ecx, 0x1c(%r14)
movq %rdx, 0x10(%rsp)
cmpl $0x3fff, %r13d          # imm = 0x3FFF
jb 0x65940
movl 0xc(%rsp), %ebp
orl $0x3fff, %ebp           # imm = 0x3FFF
movl $0x2, %r15d
cmpq 0x20(%rbx), %rax
jne 0x65906
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r15, %rsi
movq %rsi, 0x20(%rbx)
addq %rsi, %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x18(%rbx)
movw %bp, (%rdi,%rax,2)
addl $0xffffc001, %r13d      # imm = 0xFFFFC001
movq %rcx, %rax
cmpl $0x3ffe, %r13d          # imm = 0x3FFE
ja 0x658de
jmp 0x65943
movq %r14, %rdi
movq %rbx, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4b41c
movq %rax, %rcx
testl %r13d, %r13d
je 0x65998
movl 0xc(%rsp), %ebp
andl $0xc000, %ebp           # imm = 0xC000
orl %r13d, %ebp
cmpq 0x20(%rbx), %rcx
movq 0x10(%rsp), %r15
jne 0x65987
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0x20(%rbx)
addq %rsi, %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x18(%rbx)
movw %bp, (%rdi,%rcx,2)
movq %rax, %rcx
jmp 0x6599d
movq 0x10(%rsp), %r15
movl 0x18(%r14), %eax
movl %ecx, %edx
subl %eax, %edx
movl %edx, 0x1c(%r14)
movl 0xa8(%r15), %ebp
subl %r12d, %ebp
je 0x65a43
movl %r12d, %r12d
movl %ebp, %r13d
leaq (%rcx,%r13), %rax
cmpq %rax, 0x20(%rbx)
jae 0x65a1d
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x20(%rbx)
leaq 0x2(,%rcx,2), %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rcx
leaq (%rdi,%rcx,2), %rdi
addq %r12, %r12
addq 0xb8(%r15), %r12
leaq (,%r13,2), %rdx
movq %r12, %rsi
callq 0x2160
addl %ebp, 0x1c(%r14)
addq %r13, 0x18(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1cd197(%rip), %rdi    # 0x232bf0
leaq 0x1cbcf3(%rip), %rsi    # 0x231753
leaq 0x1cd1a9(%rip), %rcx    # 0x232c10
movl $0x3e5c, %edx           # imm = 0x3E5C
callq 0x2110