// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, 0x14(%rsp)
movl %r8d, %ebp
movl %ecx, 0x20(%rsp)
movq %rdi, %r14
movq 0x80(%rsp), %r8
movl 0x60(%rsp), %r15d
movq (%rdi), %r11
testq %r11, %r11
sete %cl
cmpl %ebp, %esi
setge %al
cmpl %r15d, %edx
setge %dil
orb %al, %dil
orb %cl, %dil
movl %edx, 0x1c(%rsp)
jne 0x684d0
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
xorl %ecx, %ecx
leaq 0x1bd267(%rip), %r13    # 0x225608
movl %edx, %edi
xorl %ebx, %ebx
xorl %eax, %eax
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movq 0x10(%r14), %rdx
movzwl (%rdx,%rcx,2), %r12d
movl %r12d, %ecx
shrl $0xe, %ecx
andl $0x3fff, %r12d          # imm = 0x3FFF
incl %ebx
cmpq %rbx, %r11
jbe 0x683f1
movzwl (%rdx,%rbx,2), %r10d
movl %r10d, %r9d
shrl $0xe, %r9d
cmpl %ecx, %r9d
jne 0x683f1
andl $0x3fff, %r10d          # imm = 0x3FFF
addl %r10d, %r12d
jmp 0x683cd
movzwl %cx, %ecx
movslq (%r13,%rcx,4), %rcx
addq %r13, %rcx
jmpq *%rcx
movl %r15d, %r9d
leal (%r12,%rsi), %r15d
addl %edi, %r12d
movl 0x20(%rsp), %ecx
cmpl %ecx, %esi
cmovlel %ecx, %esi
cmpl %ebp, %r15d
movl %ebp, %edx
cmovll %r15d, %edx
movl 0x14(%rsp), %ecx
cmpl %ecx, %edi
cmovlel %ecx, %edi
cmpl %r9d, %r12d
movl %r9d, %r13d
cmovll %r12d, %r9d
movl %edx, %ecx
subl %esi, %ecx
jle 0x6848f
movl %r9d, %esi
subl %edi, %esi
jle 0x6848f
cmpl %esi, %ecx
jne 0x6848f
decl %edx
decl %r9d
movl 0x10(%rsp), %esi
cmpl %esi, %ecx
movl 0xc(%rsp), %edi
cmovgl %edx, %edi
movl %edi, 0xc(%rsp)
movl 0x8(%rsp), %edi
cmovgl %r9d, %edi
movl %edi, 0x8(%rsp)
cmovgl %ecx, %esi
movl %esi, 0x10(%rsp)
cmpl 0x70(%rsp), %ecx
jl 0x6848f
movq 0x68(%rsp), %rdi
movl %r9d, %esi
xorl %r9d, %r9d
movl %eax, 0x18(%rsp)
callq 0x98063
movl 0x18(%rsp), %eax
movq 0x80(%rsp), %r8
incl %eax
movl %r12d, %edi
movl %r15d, %esi
movl %r13d, %r15d
leaq 0x1bd169(%rip), %r13    # 0x225608
jmp 0x684b7
addl %esi, %r12d
movl %r12d, %esi
jmp 0x684b7
addl %edi, %r12d
movl %r12d, %edi
jmp 0x684b7
addl %r12d, %esi
addl %r12d, %edi
movl %ebx, %ecx
movq (%r14), %r11
cmpq %rcx, %r11
jbe 0x684ec
cmpl %ebp, %esi
jge 0x684ec
cmpl %r15d, %edi
jl 0x683b7
jmp 0x684ec
xorl %eax, %eax
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movl %edx, %edi
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
movl 0x1c(%rsp), %esi
cmpl 0x14(%rsp), %esi
jl 0x68538
movl 0x10(%rsp), %ecx
testl %ecx, %ecx
jle 0x68538
cmpl 0x70(%rsp), %ecx
jge 0x68538
movslq %edi, %rdx
movslq %esi, %rsi
addq 0x78(%rsp), %rsi
cmpq %rdx, %rsi
jg 0x68538
leaq 0x24(%rsp), %r9
movl $0x3, (%r9)
movq 0x68(%rsp), %rdi
movl 0x8(%rsp), %esi
movl 0xc(%rsp), %edx
movl %eax, %ebx
callq 0x98063
movl %ebx, %eax
incl %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq