// File: /workspace/github_cpp_makefile_star2_O1/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), %eax
testl %eax, %eax
je 0x65cfd
movl 0x18(%r14), %esi
addl %eax, %esi
movq 0x18(%rbx), %rcx
cmpq %rsi, %rcx
jne 0x65d16
movq 0xa8(%rdx), %rdi
testq %rdi, %rdi
je 0x65cee
movq 0x28(%rbx), %rsi
movzwl -0x2(%rsi,%rcx,2), %ebp
movl %ebp, %esi
shrl $0xe, %esi
movq 0xb8(%rdx), %r9
movzwl (%r9), %r15d
movl %r15d, %r8d
shrl $0xe, %r8d
movl %r15d, %r13d
andl $0x3fff, %r13d          # imm = 0x3FFF
movl $0x1, %r12d
cmpq $0x1, %rdi
je 0x65b5d
movl $0x1, %r12d
movl $0x1, %r10d
movzwl (%r9,%r10,2), %r10d
movl %r10d, %r11d
shrl $0xe, %r11d
cmpl %r8d, %r11d
jne 0x65b5d
andl $0x3fff, %r10d          # imm = 0x3FFF
addl %r10d, %r13d
incl %r12d
movq %r12, %r10
cmpq %r12, %rdi
ja 0x65b37
cmpw %r8w, %si
jne 0x65b79
andl $0x3fff, %ebp           # imm = 0x3FFF
addl %ebp, %r13d
decq %rcx
movq %rcx, 0x18(%rbx)
decl %eax
movl %eax, 0x1c(%r14)
movq %rdx, 0x10(%rsp)
cmpl $0x3fff, %r13d          # imm = 0x3FFF
movl %r15d, 0xc(%rsp)
jb 0x65be8
movl %r15d, %ebp
orl $0x3fff, %ebp           # imm = 0x3FFF
movl $0x2, %r15d
movq 0x20(%rbx), %rax
cmpq %rax, 0x18(%rbx)
jne 0x65bc4
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r15, %rsi
movq %rsi, 0x20(%rbx)
movq 0x28(%rbx), %rdi
addq %rsi, %rsi
callq 0x2370
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rax
movq 0x28(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x18(%rbx)
movw %bp, (%rcx,%rax,2)
addl $0xffffc001, %r13d      # imm = 0xFFFFC001
cmpl $0x3ffe, %r13d          # imm = 0x3FFE
ja 0x65b9b
testl %r13d, %r13d
movq 0x10(%rsp), %r15
je 0x65c41
movl 0xc(%rsp), %ebp
andl $0xc000, %ebp           # imm = 0xC000
orl %r13d, %ebp
movq 0x20(%rbx), %rax
cmpq %rax, 0x18(%rbx)
jne 0x65c2d
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x20(%rbx)
movq 0x28(%rbx), %rdi
addq %rsi, %rsi
callq 0x2370
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rax
movq 0x28(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x18(%rbx)
movw %bp, (%rcx,%rax,2)
movq 0x18(%rbx), %rax
movl 0x18(%r14), %ecx
movl %eax, %edx
subl %ecx, %edx
movl %edx, 0x1c(%r14)
movl 0xa8(%r15), %ebp
subl %r12d, %ebp
je 0x65cee
movl %r12d, %r12d
movl %ebp, %r13d
addq %r13, %rax
cmpq %rax, 0x20(%rbx)
jae 0x65cc1
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)
movq 0x28(%rbx), %rdi
leaq 0x2(,%rcx,2), %rsi
callq 0x2370
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rdi
addq %rdi, %rdi
addq 0x28(%rbx), %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
movq %r14, %rdi
movq %rbx, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4bdb5
leaq 0x1c0dc3(%rip), %rdi    # 0x226ae0
leaq 0x1bf91f(%rip), %rsi    # 0x225643
leaq 0x1c0dd5(%rip), %rcx    # 0x226b00
movl $0x3e5c, %edx           # imm = 0x3E5C
callq 0x2110