// File: /workspace/github_cpp_makefile_star2_O3/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, 0x24(%rsp)
movl %r8d, %r12d
movl %ecx, 0x30(%rsp)
movl 0x70(%rsp), %ebx
movq (%rdi), %rbp
testq %rbp, %rbp
sete %r8b
cmpl %r12d, %esi
setge %cl
cmpl %ebx, %edx
setge %r9b
orb %cl, %r9b
xorl %eax, %eax
orb %r8b, %r9b
jne 0x681e2
movq 0x90(%rsp), %r8
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
xorl %r9d, %r9d
leaq 0x1c96da(%rip), %r14    # 0x231708
xorl %r13d, %r13d
xorl %eax, %eax
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
movl %edx, 0x28(%rsp)
movl %edx, %r11d
movq %rdi, 0x18(%rsp)
movq 0x10(%rdi), %rcx
movzwl (%rcx,%r9,2), %r15d
movl %r15d, %r10d
shrl $0xe, %r10d
andl $0x3fff, %r15d          # imm = 0x3FFF
incl %r13d
cmpq %r13, %rbp
jbe 0x6808a
movzwl (%rcx,%r13,2), %edx
movl %edx, %r9d
shrl $0xe, %r9d
cmpl %r10d, %r9d
jne 0x6808a
andl $0x3fff, %edx           # imm = 0x3FFF
addl %edx, %r15d
jmp 0x68066
movzwl %r10w, %ecx
movslq (%r14,%rcx,4), %rcx
addq %r14, %rcx
jmpq *%rcx
movl %ebx, %r9d
leal (%r15,%rsi), %ebx
addl %r11d, %r15d
movl 0x30(%rsp), %ecx
cmpl %ecx, %esi
cmovlel %ecx, %esi
cmpl %r12d, %ebx
movl %r12d, %edx
cmovll %ebx, %edx
movl 0x24(%rsp), %ecx
cmpl %ecx, %r11d
cmovlel %ecx, %r11d
cmpl %r9d, %r15d
movl %r9d, %r14d
cmovll %r15d, %r9d
movl %edx, %ecx
subl %esi, %ecx
jle 0x68111
movl %r9d, %esi
subl %r11d, %esi
jle 0x68111
cmpl %esi, %ecx
jne 0x68111
decl %edx
decl %r9d
movl 0x14(%rsp), %esi
cmpl %esi, %ecx
movl 0x10(%rsp), %r10d
cmovgl %edx, %r10d
movl %r10d, 0x10(%rsp)
movl 0xc(%rsp), %r10d
cmovgl %r9d, %r10d
movl %r10d, 0xc(%rsp)
cmovgl %ecx, %esi
movl %esi, 0x14(%rsp)
cmpl 0x80(%rsp), %ecx
jge 0x68155
movl %r15d, %r11d
movl %ebx, %esi
movl %r14d, %ebx
leaq 0x1c95e8(%rip), %r14    # 0x231708
movq 0x18(%rsp), %rdi
jmp 0x6813d
addl %esi, %r15d
movl %r15d, %esi
jmp 0x6813d
addl %r11d, %r15d
movl %r15d, %r11d
jmp 0x6813d
addl %r15d, %esi
addl %r15d, %r11d
movl %r13d, %r9d
cmpq %r9, %rbp
jbe 0x68190
cmpl %r12d, %esi
jge 0x68190
cmpl %ebx, %r11d
jl 0x6804f
jmp 0x68190
movq 0x78(%rsp), %rdi
movl %r9d, %esi
xorl %r9d, %r9d
movl %eax, 0x2c(%rsp)
callq 0x98ba8
movq 0x90(%rsp), %r8
movl 0x2c(%rsp), %eax
incl %eax
movq 0x18(%rsp), %rdi
movq (%rdi), %rbp
movl %r15d, %r11d
movl %ebx, %esi
movl %r14d, %ebx
leaq 0x1c957a(%rip), %r14    # 0x231708
jmp 0x6813d
movl 0x28(%rsp), %esi
cmpl 0x24(%rsp), %esi
jl 0x681e2
movl 0x14(%rsp), %ecx
testl %ecx, %ecx
jle 0x681e2
cmpl 0x80(%rsp), %ecx
jge 0x681e2
movslq %r11d, %rdx
movslq %esi, %rsi
addq 0x88(%rsp), %rsi
cmpq %rdx, %rsi
jg 0x681e2
leaq 0x34(%rsp), %r9
movl $0x3, (%r9)
movq 0x78(%rsp), %rdi
movl 0xc(%rsp), %esi
movl 0x10(%rsp), %edx
movl %eax, %ebx
callq 0x98ba8
movl %ebx, %eax
incl %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq