// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: move_gap_greedy(char*, int, int, char*, int, char*, int, unsigned int*)
inline int move_gap_greedy(char* path, int path_i, int path_length, char* x, int x_i, char* y, int y_i, unsigned int* new_error)
{
    if(path[path_i] < 2)
    {
        return 0;
    }

    /**
         * 
    GGCG-TGTGCCTGT
        *
    GGCAATGTGCCTGT
        *
    00013000000000
    **/

    int flag = 0;

    char oper = path[path_i];
    

    if(oper == 3)///there are more x
    {
        path_i++;
        y_i--;
        for (; path_i < path_length && x_i >= 0 && y_i >= 0; path_i++, x_i--, y_i--)
        {
            if(path[path_i] == 2 || path[path_i] == 3 || (path[path_i] == 0 && x[x_i] != y[y_i]))
            {
                break;
            }
            else ///path[path_i] = 1 || path[path_i] = 0, exchange path[path_i] with path[path_i-1]
            {
                if(path[path_i] == 1 && x[x_i] == y[y_i])
                {
                    path[path_i - 1] = 0;
                    (*new_error)--;
                }
                else
                {
                    path[path_i - 1] = path[path_i];
                }

                path[path_i] = oper;
                

                flag = 1;
            }
            
        }
    }
    else if(oper == 2)///there are more y
    {
        path_i++;
        x_i--;
        for (; path_i < path_length && x_i >= 0 && y_i >= 0; path_i++, x_i--, y_i--)
        {
            if(path[path_i] == 2 || path[path_i] == 3 || (path[path_i] == 0 && x[x_i] != y[y_i]))
            {
                break;
            }
            else
            {

                if(path[path_i] == 1 && x[x_i] == y[y_i])
                {
                    path[path_i - 1] = 0;
                    (*new_error)--;
                }
                else
                {
                    path[path_i - 1] = path[path_i];
                }


                path[path_i] = oper;
                flag = 1;
            }
            
        }
    }

    return flag;
}

// Assembly:
movslq %esi, %rax
movb (%rdi,%rax), %r10b
xorl %eax, %eax
cmpb $0x2, %r10b
jl 0x98b35
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq 0x38(%rsp), %r11
movl 0x30(%rsp), %ebp
movzbl %r10b, %ebx
cmpl $0x3, %ebx
je 0x98a85
cmpl $0x2, %ebx
jne 0x98b2d
leal 0x1(%rsi), %ebx
cmpl %edx, %ebx
setge %r14b
testl %r8d, %r8d
setle %r15b
testl %ebp, %ebp
sets %r12b
orb %r14b, %r15b
orb %r12b, %r15b
jne 0x98b2d
movl %r8d, %r8d
movslq %ebx, %rbx
movslq %edx, %rdx
movl %ebp, %r14d
incq %rbx
xorl %eax, %eax
movzbl -0x1(%rdi,%rbx), %ebp
testl %ebp, %ebp
je 0x98a18
cmpl $0x1, %ebp
je 0x98a2d
movl %ebp, %r15d
addl $-0x2, %r15d
cmpl $0x2, %r15d
jae 0x98a44
jmp 0x98b2d
movb -0x1(%rcx,%r8), %r15b
cmpb (%r9,%r14), %r15b
jne 0x98b2d
cmpb $0x1, %bpl
jne 0x98a44
movb -0x1(%rcx,%r8), %al
cmpb (%r9,%r14), %al
jne 0x98a44
movslq %esi, %rax
movb $0x0, (%rdi,%rax)
decl (%r11)
jmp 0x98a4b
movslq %esi, %rax
movb %bpl, (%rdi,%rax)
movb %r10b, -0x1(%rdi,%rbx)
movl $0x1, %eax
cmpq %rdx, %rbx
jge 0x98b2d
cmpq $0x2, %r8
jl 0x98b2d
leaq -0x1(%r14), %r15
incl %esi
incq %rbx
decq %r8
testq %r14, %r14
movq %r15, %r14
jg 0x989f8
jmp 0x98b2d
leal 0x1(%rsi), %ebx
cmpl %edx, %ebx
setge %r14b
testl %r8d, %r8d
sets %r15b
testl %ebp, %ebp
setle %r12b
orb %r14b, %r15b
orb %r12b, %r15b
jne 0x98b2d
movl %ebp, %r14d
movslq %ebx, %rbx
movslq %edx, %rdx
movl %r8d, %r8d
incq %rbx
xorl %eax, %eax
movzbl -0x1(%rdi,%rbx), %ebp
testl %ebp, %ebp
je 0x98ad5
cmpl $0x1, %ebp
je 0x98ae6
movl %ebp, %r15d
addl $-0x2, %r15d
cmpl $0x2, %r15d
jae 0x98afd
jmp 0x98b2d
movb (%rcx,%r8), %r15b
cmpb -0x1(%r9,%r14), %r15b
jne 0x98b2d
cmpb $0x1, %bpl
jne 0x98afd
movb (%rcx,%r8), %al
cmpb -0x1(%r9,%r14), %al
jne 0x98afd
movslq %esi, %rax
movb $0x0, (%rdi,%rax)
decl (%r11)
jmp 0x98b04
movslq %esi, %rax
movb %bpl, (%rdi,%rax)
movb %r10b, -0x1(%rdi,%rbx)
movl $0x1, %eax
cmpq %rdx, %rbx
jge 0x98b2d
testq %r8, %r8
jle 0x98b2d
decq %r8
incl %esi
incq %rbx
leaq -0x1(%r14), %r15
cmpq $0x1, %r14
movq %r15, %r14
jg 0x98ab8
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq