// File: chhylp123[P]hifiasm/ecovlp.cpp
// Function: push_correct0_fhc(window_list*, window_list_alloc*, unsigned int, unsigned int, char*)
uint64_t push_correct0_fhc(window_list *idx, window_list_alloc *res, uint32_t len0, uint32_t rc, char *qstr)
{
    uint64_t nec = 0;
    // fprintf(stderr, "[M::%s] NULL(idx)::%u\n", __func__, idx?0:1);
    if(len0 != ((uint32_t)-1)) {
        push_trace_bp_f(((asg16_v *)(&(res->c))), 0, (uint16_t)-1, (uint16_t)-1, len0, ((idx->clen>0)?1:0)); 
        idx->clen = res->c.n - idx->cidx;
    } else if(rc != ((uint32_t)-1)) {
        // fprintf(stderr, "[M::%s]\t", __func__);
        uint32_t cc = (rc<<4)>>20, cn = rc>>28, ck = 0, cs, cp;
        uint32_t bc = (rc<<20)>>20, bn = (rc<<16)>>28, btk = 0, bqk = 0, bs, bqp, btp;
        ///debug
        // prt_cigar0(cc, cn);
        // prt_bp0(bc, bn);

        for (ck = 0; ck < cn; ck++) {
            cs = (cn-1-ck)<<1; cp = (cc>>cs)&3;

            bqp = btp = (uint32_t)-1;
            if(cp != 3) {///bp == 3: more x
                bs = (bn-1-btk)<<1; btp = (bc>>bs)&3; btk++;
            }
            if(cp != 2) {///bp == 2: more y
                bqp = seq_nt6_table[(uint32_t)qstr[bqk]]; bqk++;
            }
            // fprintf(stderr, "[M::%s] cp::%u, btp::%u, bqp::%u\n", __func__, cp, btp, bqp);

            push_trace_bp_f(((asg16_v *)(&(res->c))), cp, bqp, btp, 1, ((idx->clen>0)?1:0)); 
            idx->clen = res->c.n - idx->cidx;
            // fprintf(stderr, "%c", cm[(in >> mp)&3]);

            // fprintf(stderr, "%c", "MSID"[cp]);
            if(cp != 0) nec++;
        }

        // fprintf(stderr, "\n");
    }

    return nec;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
cmpl $-0x1, -0x14(%rbp)
je 0x252e68
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movl -0x14(%rbp), %r8d
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %ecx
xorl %r9d, %r9d
movl $0x1, %eax
cmpl $0x0, %ecx
cmoval %eax, %r9d
xorl %esi, %esi
movl $0xffff, %ecx           # imm = 0xFFFF
movl %ecx, %edx
callq 0x26d790
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)
jmp 0x252fcc
cmpl $-0x1, -0x18(%rbp)
je 0x252fca
movl -0x18(%rbp), %eax
shll $0x4, %eax
shrl $0x14, %eax
movl %eax, -0x2c(%rbp)
movl -0x18(%rbp), %eax
shrl $0x1c, %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x18(%rbp), %eax
shll $0x14, %eax
shrl $0x14, %eax
movl %eax, -0x40(%rbp)
movl -0x18(%rbp), %eax
shll $0x10, %eax
shrl $0x1c, %eax
movl %eax, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x30(%rbp), %eax
jae 0x252fc8
movl -0x30(%rbp), %eax
subl $0x1, %eax
subl -0x34(%rbp), %eax
shll %eax
movl %eax, -0x38(%rbp)
movl -0x2c(%rbp), %eax
movl -0x38(%rbp), %ecx
shrl %cl, %eax
andl $0x3, %eax
movl %eax, -0x3c(%rbp)
movl $0xffffffff, -0x58(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x54(%rbp) # imm = 0xFFFFFFFF
cmpl $0x3, -0x3c(%rbp)
je 0x252f1c
movl -0x44(%rbp), %eax
subl $0x1, %eax
subl -0x48(%rbp), %eax
shll %eax
movl %eax, -0x50(%rbp)
movl -0x40(%rbp), %eax
movl -0x50(%rbp), %ecx
shrl %cl, %eax
andl $0x3, %eax
movl %eax, -0x58(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
cmpl $0x2, -0x3c(%rbp)
je 0x252f48
movq -0x20(%rbp), %rax
movl -0x4c(%rbp), %ecx
movsbl (%rax,%rcx), %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x171718(%rip), %rax    # 0x3c4650
movzbl (%rax,%rcx), %eax
movl %eax, -0x54(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movl -0x3c(%rbp), %eax
movw %ax, %dx
movl -0x54(%rbp), %eax
movw %ax, %cx
movl -0x58(%rbp), %eax
movq -0x8(%rbp), %rsi
movl 0x1c(%rsi), %r8d
xorl %r9d, %r9d
movl $0x1, %esi
cmpl $0x0, %r8d
cmoval %esi, %r9d
movl $0x1, %r8d
movzwl %dx, %esi
movzwl %cx, %edx
movzwl %ax, %ecx
callq 0x26d790
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)
cmpl $0x0, -0x3c(%rbp)
je 0x252fb8
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x252fba
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x252ebb
jmp 0x252fca
jmp 0x252fcc
movq -0x28(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)