// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x58, %rsp
movslq %ecx, %r10
movb (%rsi,%r10), %al
movb %al, -0x29(%rbp)
cmpb $0x65, %al
je 0x1727
cmpl %edx, %ecx
setg %al
testl %ecx, %ecx
sets %dil
orb %al, %dil
jne 0x1727
movl %edx, -0x34(%rbp)
movq %r8, -0x48(%rbp)
movq %r9, -0x50(%rbp)
movabsq $-0x100000000, %r11     # imm = 0xFFFFFFFF00000000
movabsq $0x100000000, %r9       # imm = 0x100000000
movq %r10, %rdx
shlq $0x20, %rdx
addq %r9, %rdx
pushq $0x3
popq %rdi
movq %r10, %rax
movb -0x29(%rbp), %r8b
movq %rax, %r14
movq %rdx, %r15
movl %edi, %ebx
decq %rax
addq %r11, %rdx
leal -0x1(%rbx), %edi
cmpb %r8b, -0x1(%rsi,%r14)
je 0x1630
movq %rcx, -0x58(%rbp)
movl %ecx, %edi
movq %rsi, -0x40(%rbp)
leaq (%rsi,%rdi), %rdx
shlq $0x20, %rdi
movabsq $-0x200000000, %r12     # imm = 0xFFFFFFFE00000000
addq %rdi, %r12
xorl %edi, %edi
movl %r8d, %ecx
movq %rdi, %r8
decl %ebx
incq %rdi
addq %r9, %r12
cmpb %cl, 0x1(%rdx,%r8)
je 0x166c
movq %rdx, -0x78(%rbp)
movl %r14d, -0x30(%rbp)
movl %ebx, %r11d
negl %r11d
pushq $0x2
popq %r8
subq %rdi, %r8
leaq (%r10,%rdi), %rdx
decq %rdx
movq %rdx, -0x60(%rbp)
pushq $-0x2
popq %r10
movq -0x40(%rbp), %r13
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
movb (%r13,%rax), %dl
cmpb $0x65, %dl
sete %r9b
cmpb %cl, %dl
sete %dl
orb %r9b, %dl
incl %r11d
addq %rsi, %r15
incq %r10
decq %r13
testb %dl, %dl
jne 0x16b0
movq -0x58(%rbp), %rcx
leal -0x1(%rcx), %edx
movb -0x29(%rbp), %sil
addq %rdi, %rdx
movq %rdx, -0x70(%rbp)
subq %r10, %rax
xorl %r9d, %r9d
movq -0x78(%rbp), %rcx
leaq (%rcx,%r9), %rdx
movb (%rdi,%rdx), %dl
cmpb $0x65, %dl
sete %r13b
cmpb %sil, %dl
sete %dl
orb %r13b, %dl
movabsq $0x100000000, %r13      # imm = 0x100000000
addq %r13, %r12
incq %r9
decl %r8d
incl %r11d
testb %dl, %dl
jne 0x16f0
cmpl $0x4, %r11d
jge 0x1738
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %ecx
cmpl $-0x1, %ebx
movq -0x58(%rbp), %r13
movq -0x70(%rbp), %rsi
jne 0x1757
cmpq $-0x1, %r10
jne 0x1757
movl %r13d, %edx
subl %r8d, %edx
cmpl %esi, %edx
jg 0x1767
cmpl $-0x1, %ebx
jne 0x177a
cmpq %r14, %rax
jge 0x177a
cmpq $0x1, %r9
jne 0x177a
movq -0x48(%rbp), %rax
movl -0x30(%rbp), %ecx
movl %ecx, (%rax)
movq -0x50(%rbp), %rax
movl %esi, (%rax)
movb $0x1, %al
jmp 0x1729
sarq $0x20, %r15
xorl %ebx, %ebx
xorl %edi, %edi
movq -0x40(%rbp), %rsi
movq -0x60(%rbp), %rax
cmpq %r15, %rax
jl 0x17d9
cmpl $0x5, %edi
jae 0x17d9
cmpb $0x65, (%rsi,%rax)
jne 0x17d2
movb %cl, (%rsi,%rax)
movl -0x34(%rbp), %edx
movl %r13d, %ecx
leaq -0x68(%rbp), %r8
leaq -0x64(%rbp), %r9
movq %rax, -0x60(%rbp)
movl %edi, %r13d
callq 0x149e
movl %r13d, %edi
movb -0x29(%rbp), %cl
movq -0x40(%rbp), %rsi
movzbl %al, %eax
addl %eax, %ebx
movq -0x60(%rbp), %rax
movq -0x58(%rbp), %r13
movb $0x65, (%rsi,%rax)
decq %rax
incl %edi
jmp 0x178a
sarq $0x20, %r12
xorl %r15d, %r15d
cmpq %r12, %r14
jg 0x1822
cmpl $0x4, %r15d
ja 0x1822
cmpb $0x65, (%rsi,%r14)
jne 0x181a
movb %cl, (%rsi,%r14)
movl -0x34(%rbp), %edx
movl %r13d, %ecx
leaq -0x68(%rbp), %r8
leaq -0x64(%rbp), %r9
callq 0x149e
movb -0x29(%rbp), %cl
movq -0x40(%rbp), %rsi
movzbl %al, %eax
addl %eax, %ebx
movb $0x65, (%rsi,%r14)
incq %r14
incl %r15d
jmp 0x17e0
cmpl $0x1, %ebx
sete %al
jne 0x1729
movq -0x48(%rbp), %rcx
movl -0x30(%rbp), %edx
movl %edx, (%rcx)
movq -0x50(%rbp), %rcx
movq -0x70(%rbp), %rdx
movl %edx, (%rcx)
jmp 0x1729