// File: /workspace/github_cpp_makefile_star2_O3/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
movzbl (%rdi,%rax), %r11d
xorl %eax, %eax
cmpb $0x2, %r11b
jl 0x9969f
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
movq 0x30(%rsp), %r10
movl 0x28(%rsp), %ebx
cmpl $0x3, %r11d
je 0x995f4
cmpl $0x2, %r11d
jne 0x99699
leal 0x1(%rsi), %r11d
cmpl %edx, %r11d
setge %bpl
testl %r8d, %r8d
setle %r14b
testl %ebx, %ebx
sets %r15b
orb %bpl, %r14b
orb %r15b, %r14b
jne 0x99699
movl %r8d, %r8d
movslq %r11d, %r11
movslq %edx, %rdx
movl %ebx, %ebx
incq %r11
xorl %eax, %eax
movzbl -0x1(%rdi,%r11), %r14d
testl %r14d, %r14d
je 0x9958f
cmpl $0x1, %r14d
je 0x9959f
leal -0x2(%r14), %ebp
cmpl $0x2, %ebp
jae 0x995b6
jmp 0x99699
movb -0x1(%rcx,%r8), %bpl
cmpb (%r9,%rbx), %bpl
je 0x995b6
jmp 0x99699
movb -0x1(%rcx,%r8), %al
cmpb (%r9,%rbx), %al
jne 0x995b6
movslq %esi, %rax
movb $0x0, (%rdi,%rax)
decl (%r10)
jmp 0x995bd
movslq %esi, %rax
movb %r14b, (%rdi,%rax)
movb $0x2, -0x1(%rdi,%r11)
movl $0x1, %eax
cmpq %rdx, %r11
jge 0x99699
cmpq $0x2, %r8
jb 0x99699
leaq -0x1(%rbx), %r14
incl %esi
incq %r11
decq %r8
testq %rbx, %rbx
movq %r14, %rbx
jg 0x99570
jmp 0x99699
leal 0x1(%rsi), %r11d
cmpl %edx, %r11d
setge %bpl
testl %r8d, %r8d
sets %r14b
testl %ebx, %ebx
setle %r15b
orb %bpl, %r14b
orb %r15b, %r14b
jne 0x99699
movl %ebx, %ebx
movslq %r11d, %r11
movslq %edx, %rdx
movl %r8d, %r8d
incq %r11
xorl %eax, %eax
movzbl -0x1(%rdi,%r11), %r14d
testl %r14d, %r14d
je 0x99644
cmpl $0x1, %r14d
je 0x99651
leal -0x2(%r14), %ebp
cmpl $0x2, %ebp
jae 0x99668
jmp 0x99699
movb (%rcx,%r8), %bpl
cmpb -0x1(%r9,%rbx), %bpl
je 0x99668
jmp 0x99699
movb (%rcx,%r8), %al
cmpb -0x1(%r9,%rbx), %al
jne 0x99668
movslq %esi, %rax
movb $0x0, (%rdi,%rax)
decl (%r10)
jmp 0x9966f
movslq %esi, %rax
movb %r14b, (%rdi,%rax)
movb $0x3, -0x1(%rdi,%r11)
movl $0x1, %eax
cmpq %rdx, %r11
jge 0x99699
testq %r8, %r8
jle 0x99699
decq %r8
incl %esi
incq %r11
leaq -0x1(%rbx), %r14
cmpq $0x1, %rbx
movq %r14, %rbx
ja 0x99628
popq %rbx
popq %r14
popq %r15
popq %rbp
retq