// File: /workspace/github_cpp_makefile_star2_O1/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, %r11
movb (%rsi,%r11), %r13b
cmpb $0x65, %r13b
je 0x1765
cmpl %edx, %ecx
setg %al
testl %ecx, %ecx
sets %dl
orb %al, %dl
jne 0x1765
movb %dl, -0x29(%rbp)
movq %r9, -0x78(%rbp)
movabsq $-0x100000000, %r14     # imm = 0xFFFFFFFF00000000
movabsq $0x100000000, %rdx      # imm = 0x100000000
movq %r11, %rax
shlq $0x20, %rax
addq %rdx, %rax
leal 0x1(%rcx), %r10d
movl $0x3, %edi
movq %r11, %rdx
movq %rdx, %rbx
movq %rax, %r15
movl %r10d, %r12d
movl %edi, %r9d
decq %rdx
addq %r14, %rax
leal -0x1(%r12), %r10d
leal -0x1(%r9), %edi
cmpb %r13b, -0x1(%rsi,%rbx)
je 0x164f
movq %rbx, -0x40(%rbp)
movq %r8, -0x70(%rbp)
movl %ecx, %edi
movq %rdi, %rax
shlq $0x20, %rax
leal -0x1(%rcx), %r8d
movl %r8d, -0x38(%rbp)
movabsq $-0x200000000, %rbx     # imm = 0xFFFFFFFE00000000
addq %rax, %rbx
movq %rsi, -0x50(%rbp)
movq %rdi, -0x48(%rbp)
leaq (%rsi,%rdi), %r14
xorl %edi, %edi
movabsq $0x100000000, %rsi      # imm = 0x100000000
movq %rdi, %rax
decl %r9d
incq %rdi
addq %rsi, %rbx
cmpb %r13b, 0x1(%r14,%rax)
je 0x16af
movl %r9d, %eax
negl %eax
addl $-0x2, %ecx
addq %rdi, %rcx
movq %r11, -0x68(%rbp)
leaq (%r11,%rdi), %rsi
decq %rsi
movq %rsi, -0x60(%rbp)
movl %r13d, %r8d
movq $-0x2, %r13
movq -0x50(%rbp), %rsi
movb (%rsi,%rdx), %r11b
cmpb $0x65, %r11b
sete %r10b
cmpb %r8b, %r11b
sete %r11b
orb %r10b, %r11b
incl %eax
movabsq $-0x100000000, %r10     # imm = 0xFFFFFFFF00000000
addq %r10, %r15
incq %r13
decl %r12d
decq %rsi
testb %r11b, %r11b
jne 0x16ea
movl -0x38(%rbp), %esi
addq %rdi, %rsi
movq %rsi, -0x38(%rbp)
subq %r13, %rdx
xorl %r11d, %r11d
leaq (%r14,%r11), %rsi
movb (%rdi,%rsi), %sil
cmpb $0x65, %sil
sete %r10b
cmpb %r8b, %sil
sete %sil
orb %r10b, %sil
movabsq $0x100000000, %r10      # imm = 0x100000000
addq %r10, %rbx
incq %r11
incl %ecx
incl %eax
testb %sil, %sil
jne 0x172d
cmpl $0x4, %eax
jge 0x1772
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %al
cmpl $-0x1, %r9d
movq -0x38(%rbp), %rsi
jne 0x178c
cmpq $-0x1, %r13
jne 0x178c
cmpl %esi, %ecx
jg 0x18e6
cmpl $-0x1, %r9d
jne 0x17a2
cmpq -0x40(%rbp), %rdx
jge 0x17a2
cmpq $0x1, %r11
je 0x18e6
xorl %eax, %eax
cmpl %r12d, %esi
movq -0x50(%rbp), %r9
movq -0x68(%rbp), %r12
movl %r8d, %r13d
movq -0x60(%rbp), %rdx
jl 0x1845
sarq $0x20, %r15
movq -0x48(%rbp), %rax
addq %r9, %rax
incq %rax
movq %rax, -0x58(%rbp)
xorl %edi, %edi
xorl %eax, %eax
cmpb $0x65, (%r9,%rdx)
jne 0x1833
movb %r13b, (%r9,%rdx)
movb (%r9,%r12), %r8b
cmpb $0x65, %r8b
sete %sil
xorl %r11d, %r11d
orb -0x29(%rbp), %sil
jne 0x182b
movl $0x5, %r11d
movq %r12, %r14
movl %r11d, %esi
leaq -0x1(%r14), %r10
leal -0x1(%rsi), %r11d
cmpb %r8b, -0x1(%r9,%r14)
movq %r10, %r14
je 0x17fb
movq -0x58(%rbp), %r11
decl %esi
leaq 0x1(%r11), %r10
cmpb %r8b, (%r11)
movq %r10, %r11
je 0x1814
xorl %r11d, %r11d
testl %esi, %esi
sete %r11b
addl %r11d, %eax
movb $0x65, (%r9,%rdx)
cmpq %r15, %rdx
jle 0x1845
decq %rdx
leal 0x1(%rdi), %esi
cmpl $0x4, %edi
movl %esi, %edi
jb 0x17d2
movq -0x40(%rbp), %rdx
cmpl %ecx, %edx
jg 0x18d6
sarq $0x20, %rbx
movq -0x48(%rbp), %rcx
addq %r9, %rcx
incq %rcx
xorl %edi, %edi
movb -0x29(%rbp), %r15b
cmpb $0x65, (%r9,%rdx)
jne 0x18c4
movb %r13b, (%r9,%rdx)
movb (%r9,%r12), %r8b
cmpb $0x65, %r8b
sete %sil
xorl %r11d, %r11d
orb %r15b, %sil
jne 0x18bc
movl $0x5, %r11d
movq %r12, %r14
movl %r11d, %esi
leaq -0x1(%r14), %r10
leal -0x1(%rsi), %r11d
cmpb %r8b, -0x1(%r9,%r14)
movq %r10, %r14
je 0x188d
movq %rcx, %r11
decl %esi
leaq 0x1(%r11), %r10
cmpb %r8b, (%r11)
movq %r10, %r11
je 0x18a5
xorl %r11d, %r11d
testl %esi, %esi
sete %r11b
addl %r11d, %eax
movb $0x65, (%r9,%rdx)
cmpq %rbx, %rdx
jge 0x18d6
incq %rdx
leal 0x1(%rdi), %esi
cmpl $0x4, %edi
movl %esi, %edi
jb 0x1865
cmpl $0x1, %eax
sete %al
movq -0x38(%rbp), %rsi
jne 0x1767
movq -0x70(%rbp), %rcx
movq -0x40(%rbp), %rdx
movl %edx, (%rcx)
movq -0x78(%rbp), %rcx
movl %esi, (%rcx)
jmp 0x1767
nop