// File: /workspace/github_cpp_makefile_star2_O3/smallHW89[P]gobang/GoBang_ChessBoard.cpp
// Function: ChessBoard::IsSide4(char*, int, int, int&, int&)
bool ChessBoard::IsSide4(char oneLine[], int len , int pos, int &resL, int &resR)
{
    char side = oneLine[pos];
    if( Chess_Empty == side  )
        return  false;
    if( pos > len || pos<0 )
        return false;
    if( side != oneLine[pos])
        return false;

    int ri =pos, li=pos;
    int rr =pos, ll=pos;
    while( oneLine[li-1] == side )  li--;
    while( oneLine[ri+1] == side )  ri++;
    rr = ri; ll = li; 
    while( oneLine[ll-1] == Chess_Empty || oneLine[ll-1] == side ) ll--;
    while( oneLine[rr+1] == Chess_Empty || oneLine[rr+1] == side ) rr++;

    if(rr - ll +1 < 5)
        return false;
    
    int cnt = ri - li +1; 
    if(cnt ==4 &&  ll == li && rr > ri)
    {
        resL= li;
        resR= ri;   
        return true;
    }
    if(cnt == 4 &&  rr == ri && ll < li  )
    {
        resL = li;
        resR = ri;
        return true;
    }
    cnt = 0; 
    //向左尝试放4个
    int kk=0, ii=0, rL = 0, rR = 0;
    for( kk = ri ; kk>=ll && ii<5 ; kk--, ii++)
    {
        if (oneLine[kk] != Chess_Empty)
            continue;
        oneLine[kk] = side;

        bool res = Is5(oneLine,len ,pos, rL, rR );
        if(res )
            cnt++;
        oneLine[kk] = Chess_Empty;
    }
    //向右4个
    ii=0;
    for( kk = li ; kk<=rr  && ii<5 ; kk++ ,ii++)
    {
        if (oneLine[kk] != Chess_Empty)
            continue;
        oneLine[kk] = side;

        bool res = Is5(oneLine,len ,pos, rL, rR );
        if(res )
            cnt++;
        oneLine[kk] = Chess_Empty;
    }
    if(cnt == 1)
    {
        resL = li;
        resR = ri;
        return true;
    }
    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movslq %ecx, %r12
movb (%rsi,%r12), %r11b
cmpb $0x65, %r11b
je 0x172a
cmpl %edx, %ecx
setg %al
testl %ecx, %ecx
sets %dl
orb %al, %dl
jne 0x172a
movq %r8, -0x68(%rbp)
movabsq $-0x100000000, %r10     # imm = 0xFFFFFFFF00000000
movabsq $0x100000000, %r15      # imm = 0x100000000
movq %r12, %rax
shlq $0x20, %rax
addq %r15, %rax
leal 0x1(%rcx), %edi
movl $0x3, %r8d
movq %r12, -0x48(%rbp)
movq %r12, %rdx
movq %rax, %rbx
movl %edi, %r13d
movl %r8d, %r14d
decq %r12
addq %r10, %rax
leal -0x1(%r13), %edi
leal -0x1(%r14), %r8d
cmpb %r11b, -0x1(%rsi,%rdx)
je 0x161b
movq %rdx, -0x38(%rbp)
movq %r9, -0x70(%rbp)
movl %ecx, %edx
movq %rdx, %rax
shlq $0x20, %rax
leal -0x1(%rcx), %r8d
movl %r8d, -0x30(%rbp)
movabsq $-0x200000000, %r10     # imm = 0xFFFFFFFE00000000
addq %rax, %r10
movq %rsi, -0x50(%rbp)
movq %rdx, -0x40(%rbp)
leaq (%rsi,%rdx), %r8
xorl %eax, %eax
movq %rax, %rsi
decl %r14d
incq %rax
addq %r15, %r10
cmpb %r11b, 0x1(%r8,%rsi)
je 0x1670
movl %r14d, %r15d
negl %r15d
addl $-0x2, %ecx
addq %rax, %rcx
movq -0x48(%rbp), %rsi
leaq (%rsi,%rax), %rdx
decq %rdx
movq %rdx, -0x60(%rbp)
movq $-0x2, %r9
movq -0x50(%rbp), %rsi
movl %r11d, %edx
movb (%rsi,%r12), %r11b
cmpb $0x65, %r11b
sete %dil
cmpb %dl, %r11b
sete %r11b
orb %dil, %r11b
incl %r15d
movabsq $-0x100000000, %rdi     # imm = 0xFFFFFFFF00000000
addq %rdi, %rbx
incq %r9
decl %r13d
decq %rsi
testb %r11b, %r11b
jne 0x16ac
movl -0x30(%rbp), %esi
addq %rax, %rsi
movq %rsi, -0x30(%rbp)
subq %r9, %r12
xorl %r11d, %r11d
leaq (%r8,%r11), %rsi
movb (%rax,%rsi), %sil
cmpb $0x65, %sil
sete %dil
cmpb %dl, %sil
sete %sil
orb %dil, %sil
movabsq $0x100000000, %rdi      # imm = 0x100000000
addq %rdi, %r10
incq %r11
incl %ecx
incl %r15d
testb %sil, %sil
jne 0x16f0
cmpl $0x4, %r15d
jge 0x1737
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %edx, %eax
cmpl $-0x1, %r14d
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rsi
jne 0x1755
cmpq $-0x1, %r9
jne 0x1755
cmpl %esi, %ecx
jg 0x18a5
cmpl $-0x1, %r14d
jne 0x176a
cmpq %rdx, %r12
jge 0x176a
cmpq $0x1, %r11
je 0x18a5
xorl %r12d, %r12d
cmpl %r13d, %esi
movq -0x50(%rbp), %r15
movq -0x48(%rbp), %r13
movl %eax, %edi
movq -0x60(%rbp), %r9
jl 0x180d
sarq $0x20, %rbx
movq -0x40(%rbp), %rsi
leaq (%rsi,%r15), %rdx
incq %rdx
movq %rdx, -0x58(%rbp)
xorl %r8d, %r8d
xorl %r12d, %r12d
cmpb $0x65, (%r15,%r9)
jne 0x17f8
movb %dil, (%r15,%r9)
movb (%r15,%r13), %sil
cmpb $0x65, %sil
je 0x17f3
movq %r9, %rdx
movl $0x5, %r11d
movq %r13, %r14
movl %r11d, %r9d
leaq -0x1(%r14), %rdi
leal -0x1(%r9), %r11d
cmpb %sil, -0x1(%r15,%r14)
movq %rdi, %r14
je 0x17be
movq -0x58(%rbp), %r11
decl %r9d
leaq 0x1(%r11), %rdi
cmpb %sil, (%r11)
movq %rdi, %r11
je 0x17d7
cmpl $0x1, %r9d
adcl $0x0, %r12d
movl %eax, %edi
movq %rdx, %r9
movb $0x65, (%r15,%r9)
cmpq %rbx, %r9
jle 0x180d
decq %r9
leal 0x1(%r8), %esi
cmpl $0x4, %r8d
movl %esi, %r8d
jb 0x179d
movq -0x38(%rbp), %rdx
cmpl %ecx, %edx
jg 0x1893
sarq $0x20, %r10
movq -0x40(%rbp), %rcx
leaq (%rcx,%r15), %r14
incq %r14
xorl %r8d, %r8d
movq %rdx, %rcx
cmpb $0x65, (%r15,%rcx)
jne 0x187e
movb %dil, (%r15,%rcx)
movb (%r15,%r13), %sil
cmpb $0x65, %sil
je 0x1879
movl $0x5, %r11d
movq %r13, %rbx
movl %r11d, %r9d
leaq -0x1(%rbx), %rdi
leal -0x1(%r9), %r11d
cmpb %sil, -0x1(%r15,%rbx)
movq %rdi, %rbx
je 0x1848
movq %r14, %r11
decl %r9d
leaq 0x1(%r11), %rdi
cmpb %sil, (%r11)
movq %rdi, %r11
je 0x1860
cmpl $0x1, %r9d
adcl $0x0, %r12d
movl %eax, %edi
movb $0x65, (%r15,%rcx)
cmpq %r10, %rcx
jge 0x1893
incq %rcx
leal 0x1(%r8), %esi
cmpl $0x4, %r8d
movl %esi, %r8d
jb 0x182a
cmpl $0x1, %r12d
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
jne 0x172a
movq -0x68(%rbp), %rax
movl %edx, (%rax)
movq -0x70(%rbp), %rax
movl %esi, (%rax)
movb $0x1, %al
jmp 0x172c