// File: chhylp123[P]hifiasm/Correct.cpp
// Function: extract_exact_cigar(asg16_v*, int, int, int, int, int, int, Candidates_list*, int, long, long)
uint32_t extract_exact_cigar(asg16_v *ez, int32_t ps, int32_t ts, int32_t pmin, int32_t pmax, 
int32_t tmin, int32_t tmax, Candidates_list *res, int32_t minl, int64_t min_w_l, int64_t h_khit)
{
    uint32_t ci = 0, cl, occ = 0; uint16_t c; 
    int32_t pi = ps, ti = ts, p[2], t[2], poff, toff, maxl;
    int32_t pos, poe, tos, toe, l; poff = toff = maxl = -1;
    while (ci < ez->n && pi < pmax && ti < tmax) {
        ci = pop_trace(ez, ci, &c, &cl);
        if(c == 0) {
            p[0] = pi; p[1] = pi + cl;
            t[0] = ti; t[1] = ti + cl;
            pos = MAX(p[0], pmin); poe = MIN(p[1], pmax);
            tos = MAX(t[0], tmin); toe = MIN(t[1], tmax);
            if((poe > pos) && (toe > tos)) {
                l = poe - pos;
                if(l == (toe - tos)) {
                    poe--; toe--;
                    if(l > maxl) {
                        poff = poe; toff = toe; maxl = l;
                    }
                    if(l >= minl) {
                        push_khit(res, toe, poe, l, h_khit, NULL); occ++;
                    }
                }
            }
            pi+=cl; ti+=cl;
        } else if(c == 1) {
            pi+=cl; ti+=cl;
        } else if(c == 2) {///more p
            pi+=cl;
        } else if(c == 3) {
            ti+=cl;
        }
    }
    ///(ts >= tmin) && (ti >= (min_w_l + ts)): here is a whole window
    if(maxl > 0 && maxl < minl && (ts >= tmin) && (ti >= (min_w_l + ts))) {
        uint32_t w = 3;
        push_khit(res, toff, poff, maxl, h_khit, &w); occ++;
    }
    return occ;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movl %r9d, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x28(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x34(%rbp)
movl $0xffffffff, -0x50(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x4c(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
movl -0x20(%rbp), %eax
movl %eax, %ecx
movq -0x8(%rbp), %rdx
xorl %eax, %eax
cmpq (%rdx), %rcx
movb %al, -0x69(%rbp)
jae 0x6481d
movl -0x30(%rbp), %ecx
xorl %eax, %eax
cmpl -0x18(%rbp), %ecx
movb %al, -0x69(%rbp)
jge 0x6481d
movl -0x34(%rbp), %eax
cmpl 0x10(%rbp), %eax
setl %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x64829
jmp 0x649c2
movq -0x8(%rbp), %rdi
movl -0x20(%rbp), %esi
leaq -0x2a(%rbp), %rdx
leaq -0x24(%rbp), %rcx
callq 0xa1ee0
movl %eax, -0x20(%rbp)
movzwl -0x2a(%rbp), %eax
cmpl $0x0, %eax
jne 0x64974
movl -0x30(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x30(%rbp), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x34(%rbp), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jl 0x6487b
movl -0x3c(%rbp), %eax
movl %eax, -0x70(%rbp)
jmp 0x64881
movl -0x14(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x18(%rbp), %eax
jg 0x64897
movl -0x38(%rbp), %eax
movl %eax, -0x74(%rbp)
jmp 0x6489d
movl -0x18(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jl 0x648b3
movl -0x44(%rbp), %eax
movl %eax, -0x78(%rbp)
jmp 0x648b9
movl -0x1c(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x40(%rbp), %eax
cmpl 0x10(%rbp), %eax
jg 0x648cf
movl -0x40(%rbp), %eax
movl %eax, -0x7c(%rbp)
jmp 0x648d5
movl 0x10(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
jle 0x64960
movl -0x60(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jle 0x64960
movl -0x58(%rbp), %eax
subl -0x54(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
movl -0x60(%rbp), %ecx
subl -0x5c(%rbp), %ecx
cmpl %ecx, %eax
jne 0x6495e
movl -0x58(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x58(%rbp)
movl -0x60(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x60(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x50(%rbp), %eax
jle 0x6492d
movl -0x58(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x64(%rbp), %eax
cmpl 0x20(%rbp), %eax
jl 0x6495c
movq 0x18(%rbp), %rdi
movl -0x60(%rbp), %esi
movl -0x58(%rbp), %edx
movl -0x64(%rbp), %ecx
movq 0x30(%rbp), %rax
movl %eax, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0xc11f0
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x6495e
jmp 0x64960
movl -0x24(%rbp), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x24(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x649bd
movzwl -0x2a(%rbp), %eax
cmpl $0x1, %eax
jne 0x64991
movl -0x24(%rbp), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x24(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x649bb
movzwl -0x2a(%rbp), %eax
cmpl $0x2, %eax
jne 0x649a5
movl -0x24(%rbp), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x649b9
movzwl -0x2a(%rbp), %eax
cmpl $0x3, %eax
jne 0x649b7
movl -0x24(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x649b9
jmp 0x649bb
jmp 0x649bd
jmp 0x647f1
cmpl $0x0, -0x50(%rbp)
jle 0x64a19
movl -0x50(%rbp), %eax
cmpl 0x20(%rbp), %eax
jge 0x64a19
movl -0x10(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jl 0x64a19
movslq -0x34(%rbp), %rax
movq 0x28(%rbp), %rcx
movslq -0x10(%rbp), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jl 0x64a19
movl $0x3, -0x68(%rbp)
movq 0x18(%rbp), %rdi
movl -0x4c(%rbp), %esi
movl -0x48(%rbp), %edx
movl -0x50(%rbp), %ecx
movq 0x30(%rbp), %rax
movl %eax, %r8d
leaq -0x68(%rbp), %r9
callq 0xc11f0
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)