// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movl %r9d, 0x28(%rsp)
movl %r8d, %r12d
movl %ecx, 0x30(%rsp)
movq %rdi, %rbp
movq $0x0, 0x10(%rsp)
pushq $-0x1
popq %rax
leaq 0x1ac8bf(%rip), %r15    # 0x1e3658
movl %edx, 0x2c(%rsp)
movl %edx, %edi
movl %eax, 0x18(%rsp)
movl %eax, 0x1c(%rsp)
movl %eax, 0x20(%rsp)
xorl %ebx, %ebx
movl %edi, %r14d
movl %ebx, %eax
cmpq %rax, (%rbp)
jbe 0x36edc
movl %esi, %r13d
cmpl %r12d, %esi
jge 0x36edc
cmpl 0x70(%rsp), %r14d
jge 0x36edc
movq %rbp, %rdi
movl %ebx, %esi
leaq 0x26(%rsp), %rdx
leaq 0xc(%rsp), %rcx
callq 0x53a7d
movl %eax, %ebx
movzwl 0x26(%rsp), %eax
movl %r14d, %edi
movl %r13d, %esi
cmpq $0x3, %rax
ja 0x36dad
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movl 0xc(%rsp), %edi
leal (%rdi,%r13), %esi
addl %r14d, %edi
movl 0x30(%rsp), %r9d
cmpl %r9d, %r13d
cmovgl %r13d, %r9d
cmpl %r12d, %esi
movl %r12d, %edx
cmovll %esi, %edx
movl 0x28(%rsp), %r8d
cmpl %r8d, %r14d
cmovgl %r14d, %r8d
movl 0x70(%rsp), %eax
cmpl %eax, %edi
cmovll %edi, %eax
movl %edx, %ecx
subl %r9d, %ecx
jle 0x36dad
movl %eax, %r9d
subl %r8d, %r9d
jle 0x36dad
cmpl %r9d, %ecx
jne 0x36dad
decl %edx
decl %eax
movl 0x20(%rsp), %r9d
cmpl %r9d, %ecx
movl 0x1c(%rsp), %r8d
cmovgl %edx, %r8d
movl %r8d, 0x1c(%rsp)
movl 0x18(%rsp), %r8d
cmovgl %eax, %r8d
movl %r8d, 0x18(%rsp)
cmovgl %ecx, %r9d
movl %r9d, 0x20(%rsp)
cmpl 0x80(%rsp), %ecx
jl 0x36dad
movq 0x78(%rsp), %rdi
movl %eax, %esi
movl 0x90(%rsp), %r8d
xorl %r9d, %r9d
callq 0x6293f
movq 0x10(%rsp), %rax
incl %eax
movq %rax, 0x10(%rsp)
movl 0xc(%rsp), %eax
addl %eax, %r13d
addl %eax, %r14d
jmp 0x36ed1
addl 0xc(%rsp), %r13d
jmp 0x36ed1
addl 0xc(%rsp), %r14d
movl %r14d, %edi
movl %r13d, %esi
jmp 0x36dad
movl 0x2c(%rsp), %edx
cmpl 0x28(%rsp), %edx
jl 0x36f0a
movl 0x20(%rsp), %ecx
testl %ecx, %ecx
jle 0x36f0a
cmpl 0x80(%rsp), %ecx
jge 0x36f0a
movslq %r14d, %rax
movslq %edx, %rdx
addq 0x88(%rsp), %rdx
cmpq %rax, %rdx
jle 0x36f11
movq 0x10(%rsp), %rax
jmp 0x36f3e
leaq 0x34(%rsp), %r9
movl $0x3, (%r9)
movq 0x78(%rsp), %rdi
movl 0x18(%rsp), %esi
movl 0x1c(%rsp), %edx
movl 0x90(%rsp), %r8d
callq 0x6293f
movq 0x10(%rsp), %rax
incl %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq