// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
movslq %ecx, %r11
movb (%rsi,%r11), %r14b
cmpb $0x65, %r14b
je 0x1d96
cmpl %edx, %ecx
setg %al
testl %ecx, %ecx
sets %dil
orb %al, %dil
je 0x1da9
xorl %edi, %edi
movl %edi, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ecx, -0x48(%rbp)
movl %edx, -0x2c(%rbp)
movq %r8, -0x78(%rbp)
movq %r9, -0x80(%rbp)
movq %rsi, -0x38(%rbp)
leaq (%rsi,%r11), %rdi
movl %r11d, %eax
movq %rax, -0x40(%rbp)
movabsq $-0x100000000, %r8      # imm = 0xFFFFFFFF00000000
movq %r11, %rax
shlq $0x20, %rax
movabsq $0x200000000, %r13      # imm = 0x200000000
addq %rax, %r13
xorl %ebx, %ebx
movq %rbx, %rax
decq %rbx
addq %r8, %r13
cmpb %r14b, -0x1(%rdi,%rax)
je 0x1de6
movabsq $0x100000000, %rax      # imm = 0x100000000
movq -0x40(%rbp), %rcx
movq %rcx, %rdx
shlq $0x20, %rdx
movabsq $-0x200000000, %r15     # imm = 0xFFFFFFFE00000000
addq %rdx, %r15
movl $0xfffffffc, %esi       # imm = 0xFFFFFFFC
subl %ebx, %esi
addq %rbx, %rdi
movq $-0x2, %r10
movq $-0x2, %rdx
subq %rbx, %rdx
movq %r11, -0x50(%rbp)
leaq (%r11,%rbx), %r9
incq %r9
movq %r9, -0x68(%rbp)
movq $-0x1, %r11
movq -0x38(%rbp), %r9
movq %r9, %r12
incl %esi
incq %r9
incq %r10
addq %rax, %r15
incq %r11
cmpb %r14b, 0x1(%r12,%rcx)
je 0x1e4d
addq %rcx, %rbx
incq %rbx
movq %rbx, -0x60(%rbp)
addq %rcx, %r9
leaq (%rcx,%r10), %r12
movq -0x50(%rbp), %rcx
leaq (%rcx,%r10), %rbx
incq %rbx
movb (%rdi), %cl
cmpb $0x65, %cl
sete %r10b
cmpb %r14b, %cl
sete %cl
orb %r10b, %cl
incl %esi
addq %r8, %r13
incl %edx
decq %rdi
testb %cl, %cl
jne 0x1e81
movq -0x40(%rbp), %r8
addq %r11, %r8
movb (%r9), %cl
cmpb $0x65, %cl
sete %dil
cmpb %r14b, %cl
sete %cl
orb %dil, %cl
addq %rax, %r15
incl %esi
incl %r12d
incq %r9
testb %cl, %cl
jne 0x1ea8
xorl %edi, %edi
cmpl $0x4, %esi
jl 0x1d98
movl -0x48(%rbp), %eax
subl %edx, %eax
movq %r8, -0x70(%rbp)
cmpl %eax, %r8d
movq -0x38(%rbp), %rsi
movq -0x68(%rbp), %rcx
jl 0x1f45
movq %rbx, %rdx
sarq $0x20, %r13
xorl %ebx, %ebx
xorl %edi, %edi
cmpb $0x65, (%rsi,%rdx)
jne 0x1f33
movb %r14b, (%rsi,%rdx)
movq %rdx, -0x48(%rbp)
movl -0x2c(%rbp), %edx
movq -0x40(%rbp), %rcx
leaq -0x58(%rbp), %r8
leaq -0x54(%rbp), %r9
movl %edi, -0x50(%rbp)
callq 0x18b8
movq -0x48(%rbp), %rdx
movl -0x50(%rbp), %edi
movq -0x68(%rbp), %rcx
movq -0x38(%rbp), %rsi
movzbl %al, %eax
addl %eax, %edi
movb $0x65, (%rsi,%rdx)
cmpq %r13, %rdx
jle 0x1f45
decq %rdx
leal 0x1(%rbx), %eax
cmpl $0x2, %ebx
movl %eax, %ebx
jb 0x1ef6
cmpl %r12d, -0x60(%rbp)
jg 0x1f9b
sarq $0x20, %r15
xorl %ebx, %ebx
cmpb $0x65, (%rsi,%rcx)
jne 0x1f89
movb %r14b, (%rsi,%rcx)
movl -0x2c(%rbp), %edx
movq %rcx, %r12
movq -0x40(%rbp), %rcx
leaq -0x58(%rbp), %r8
leaq -0x54(%rbp), %r9
movl %edi, %r13d
callq 0x18b8
movl %r13d, %edi
movq %r12, %rcx
movq -0x38(%rbp), %rsi
movzbl %al, %eax
addl %eax, %edi
movb $0x65, (%rsi,%r12)
cmpq %r15, %rcx
jge 0x1f9b
incq %rcx
leal 0x1(%rbx), %eax
cmpl $0x2, %ebx
movl %eax, %ebx
jb 0x1f51
testl %edi, %edi
setg %dil
jle 0x1d98
movq -0x78(%rbp), %rax
movq -0x60(%rbp), %rcx
movl %ecx, (%rax)
movq -0x80(%rbp), %rax
movq -0x70(%rbp), %rcx
movl %ecx, (%rax)
jmp 0x1d98