// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
movslq %esi, %rsi
movzbl (%rdi,%rsi), %ebx
xorl %eax, %eax
cmpb $0x2, %bl
jl 0x63769
movq 0x30(%rsp), %r10
movl 0x28(%rsp), %r11d
cmpl $0x3, %ebx
je 0x636f4
cmpl $0x2, %ebx
jne 0x63769
movl %r8d, %r8d
movslq %edx, %rdx
incq %rsi
xorl %eax, %eax
movl $0x1, %ebx
cmpq %rdx, %rsi
jge 0x63769
testl %r8d, %r8d
jle 0x63769
testl %r11d, %r11d
js 0x63769
movzbl (%rdi,%rsi), %r14d
movl %r11d, %r15d
testl %r14d, %r14d
je 0x636b9
cmpl $0x1, %r14d
je 0x636c9
leal -0x2(%r14), %ebp
cmpl $0x2, %ebp
jae 0x636de
jmp 0x63769
movb -0x1(%rcx,%r8), %bpl
cmpb (%r9,%r15), %bpl
je 0x636de
jmp 0x63769
movb -0x1(%rcx,%r8), %al
cmpb (%r9,%r15), %al
jne 0x636de
movb $0x0, -0x1(%rdi,%rsi)
decl (%r10)
jmp 0x636e3
movb %r14b, -0x1(%rdi,%rsi)
movb $0x2, (%rdi,%rsi)
decl %r11d
incq %rsi
decq %r8
movl %ebx, %eax
jmp 0x6367d
movl %r11d, %r11d
movslq %edx, %rdx
incq %rsi
xorl %eax, %eax
movl $0x1, %ebx
cmpq %rdx, %rsi
jge 0x63769
testl %r8d, %r8d
js 0x63769
testl %r11d, %r11d
jle 0x63769
movzbl (%rdi,%rsi), %r14d
movl %r8d, %r15d
testl %r14d, %r14d
je 0x63731
cmpl $0x1, %r14d
je 0x6373e
leal -0x2(%r14), %ebp
cmpl $0x2, %ebp
jae 0x63753
jmp 0x63769
movb (%rcx,%r15), %bpl
cmpb -0x1(%r9,%r11), %bpl
je 0x63753
jmp 0x63769
movb (%rcx,%r15), %al
cmpb -0x1(%r9,%r11), %al
jne 0x63753
movb $0x0, -0x1(%rdi,%rsi)
decl (%r10)
jmp 0x63758
movb %r14b, -0x1(%rdi,%rsi)
movb $0x3, (%rdi,%rsi)
decl %r8d
incq %rsi
decq %r11
movl %ebx, %eax
jmp 0x63704
popq %rbx
popq %r14
popq %r15
popq %rbp
retq