// File: /workspace/github_cpp_makefile_star2_O2/smallHW89[P]gobang/GoBang_ChessBoard.cpp
// Function: ChessBoard::IsOpen2(char*, int, int, int&, int&)
bool ChessBoard::IsOpen2(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 = 0;
    //向左尝试放3个
    int kk=0, ii=0, rL = 0, rR = 0;
    for( kk = ri ; kk>=ll && ii<3 ; kk--, ii++)
    {
        if (oneLine[kk] != Chess_Empty)
            continue;
        oneLine[kk] = side;

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

        bool res = IsOpen3(oneLine,len ,pos, rL, rR );
        if(res )
            cnt++;
        oneLine[kk] = Chess_Empty;
    }
    if(cnt > 0 )
    {
        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 $0x48, %rsp
movslq %ecx, %r11
movb (%rsi,%r11), %r12b
cmpb $0x65, %r12b
je 0x1ca4
cmpl %edx, %ecx
setg %al
testl %ecx, %ecx
sets %dil
orb %al, %dil
je 0x1cb7
xorl %edi, %edi
movl %edi, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r9, -0x70(%rbp)
leaq (%rsi,%r11), %rbx
movl %r11d, %eax
movq %rax, -0x38(%rbp)
movabsq $-0x100000000, %r15     # imm = 0xFFFFFFFF00000000
movq %r11, %rax
shlq $0x20, %rax
leaq -0x1(%r11), %r14
movabsq $0x200000000, %r13      # imm = 0x200000000
addq %rax, %r13
xorl %r10d, %r10d
movq %r10, %rax
decq %r10
addq %r15, %r13
cmpb %r12b, -0x1(%rbx,%rax)
je 0x1ceb
movabsq $0x100000000, %rax      # imm = 0x100000000
movb %r12b, -0x29(%rbp)
movq -0x38(%rbp), %rdi
movq %rdi, %r9
shlq $0x20, %r9
movq %rsi, -0x40(%rbp)
addq %rsi, %rdi
movabsq $-0x200000000, %r12     # imm = 0xFFFFFFFE00000000
addq %r9, %r12
movb -0x29(%rbp), %r9b
pushq $-0x4
popq %rsi
subl %r10d, %esi
addq %r10, %rbx
addq %r10, %r11
incq %r11
movq %r11, -0x58(%rbp)
movq %rdi, %r11
incq %rdi
incl %esi
addq %rax, %r12
incq %r14
cmpb %r9b, 0x1(%r11)
je 0x1d3f
movq -0x38(%rbp), %r11
addq %r11, %r10
incq %r10
movq %r10, -0x68(%rbp)
movb (%rbx), %r11b
cmpb $0x65, %r11b
sete %r10b
cmpb %r9b, %r11b
sete %r11b
orb %r10b, %r11b
incl %esi
addq %r15, %r13
decq %rbx
testb %r11b, %r11b
jne 0x1d61
movb (%rdi), %r10b
cmpb $0x65, %r10b
sete %r11b
cmpb %r9b, %r10b
sete %r10b
orb %r11b, %r10b
addq %rax, %r12
incl %esi
incq %rdi
testb %r10b, %r10b
jne 0x1d83
xorl %edi, %edi
cmpl $0x4, %esi
jl 0x1ca6
movl %edx, -0x30(%rbp)
movl %ecx, -0x44(%rbp)
movq %r8, -0x60(%rbp)
sarq $0x20, %r13
movq %r14, %r15
xorl %ebx, %ebx
movq -0x40(%rbp), %rsi
movq -0x58(%rbp), %rax
cmpq %r13, %r15
jl 0x1e17
cmpl $0x3, %ebx
jae 0x1e17
cmpb $0x65, (%rsi,%r15)
jne 0x1e10
movb %r9b, (%rsi,%r15)
movl -0x30(%rbp), %edx
movq -0x38(%rbp), %rcx
leaq -0x50(%rbp), %r8
leaq -0x4c(%rbp), %r9
movl %edi, -0x48(%rbp)
callq 0x1846
movl -0x48(%rbp), %edi
movb -0x29(%rbp), %r9b
movq -0x40(%rbp), %rsi
movzbl %al, %eax
addl %eax, %edi
movq -0x58(%rbp), %rax
movb $0x65, (%rsi,%r15)
decq %r15
incl %ebx
jmp 0x1dcb
sarq $0x20, %r12
xorl %r13d, %r13d
cmpq %r12, %rax
jg 0x1e6b
cmpl $0x2, %r13d
ja 0x1e6b
cmpb $0x65, (%rsi,%rax)
jne 0x1e63
movb %r9b, (%rsi,%rax)
movl -0x30(%rbp), %edx
movl -0x44(%rbp), %ecx
leaq -0x50(%rbp), %r8
leaq -0x4c(%rbp), %r9
movq %rax, %rbx
movl %edi, %r15d
callq 0x1846
movl %r15d, %edi
movb -0x29(%rbp), %r9b
movq -0x40(%rbp), %rsi
movzbl %al, %eax
addl %eax, %edi
movq %rbx, %rax
movb $0x65, (%rsi,%rbx)
incq %rax
incl %r13d
jmp 0x1e1e
testl %edi, %edi
setg %dil
jle 0x1ca6
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
movl %ecx, (%rax)
movq -0x70(%rbp), %rax
movl %r14d, (%rax)
jmp 0x1ca6
nop