// File: chhylp123[P]hifiasm/Correct.cpp
// Function: scan_cigar_interval(window_list*, window_list_alloc*, long*, long, long)
int scan_cigar_interval(window_list *idx, window_list_alloc *cc, int64_t* get_error, int64_t scanXbeg, int64_t scanXend)
{
    uint8_t c; uint32_t cl;
    (*get_error) = -1;
     if(idx->clen == 1) {
        get_cigar_cell(idx, cc, 0, &c, &cl);
        if(c == 0) {
            (*get_error) = 0;
            return 1;
        }
    }



    int32_t x_i = 0, y_i = 0, c_i, c_n = idx->clen, c_err = 0;
    uint32_t i;
    

    ///0 is match, 1 is mismatch, 2 is up, 3 is left
    ///2: there are more bases at y, 3: there are more bases at x
    for (c_i = 0; c_i < c_n; c_i++) {
        get_cigar_cell(idx, cc, c_i, &c, &cl);
        if (c == 0) {//match
            for (i = 0; i < cl; i++) {
                if(x_i == scanXbeg) c_err = 0;
                x_i++; y_i++;

                if(x_i == scanXend + 1) {
                    (*get_error) = c_err;
                    return 1;
                }
            }
        } else if (c == 1) {//mismatch
            for (i = 0; i < cl; i++) {
                if(x_i == scanXbeg) c_err = 0;
                x_i++; y_i++; c_err++;

                if(x_i == scanXend + 1) {
                    (*get_error) = c_err;
                    return 1;
                }
            }
        } else if (c == 2) {///y has more bases than x
            c_err += cl; y_i += cl;
        }
        else if (c == 3) {
            for (i = 0; i < cl; i++) {
                if(x_i == scanXbeg) c_err = 0;
                x_i++; c_err++;

                if(x_i == scanXend + 1) {
                    (*get_error) = c_err;
                    return 1;
                }
            }
        }
    }

    (*get_error) = c_err;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq $-0x1, (%rax)
movq -0x10(%rbp), %rax
cmpl $0x1, 0x1c(%rax)
jne 0x3548a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
xorl %edx, %edx
leaq -0x31(%rbp), %rcx
leaq -0x38(%rbp), %r8
callq 0x2c960
movzbl -0x31(%rbp), %eax
cmpl $0x0, %eax
jne 0x35488
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x3567b
jmp 0x3548a
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x35669
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x44(%rbp), %edx
leaq -0x31(%rbp), %rcx
leaq -0x38(%rbp), %r8
callq 0x2c960
movzbl -0x31(%rbp), %eax
cmpl $0x0, %eax
jne 0x35549
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0x35544
movslq -0x3c(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0x354fd
movl $0x0, -0x4c(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movslq -0x3c(%rbp), %rax
movq -0x30(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jne 0x35537
movslq -0x4c(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x3567b
jmp 0x35539
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x354e4
jmp 0x35659
movzbl -0x31(%rbp), %eax
cmpl $0x1, %eax
jne 0x355c7
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0x355c2
movslq -0x3c(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0x35572
movl $0x0, -0x4c(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movslq -0x3c(%rbp), %rax
movq -0x30(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jne 0x355b5
movslq -0x4c(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x3567b
jmp 0x355b7
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x35559
jmp 0x35657
movzbl -0x31(%rbp), %eax
cmpl $0x2, %eax
jne 0x355e4
movl -0x38(%rbp), %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x38(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x35655
movzbl -0x31(%rbp), %eax
cmpl $0x3, %eax
jne 0x35653
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0x35651
movslq -0x3c(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0x3560d
movl $0x0, -0x4c(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movslq -0x3c(%rbp), %rax
movq -0x30(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jne 0x35644
movslq -0x4c(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x3567b
jmp 0x35646
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x355f4
jmp 0x35653
jmp 0x35655
jmp 0x35657
jmp 0x35659
jmp 0x3565b
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x354b0
movslq -0x4c(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)