// File: /workspace/github_cpp_makefile_star2_O1/SethKasmann[P]clever-girl/src/state.cpp
// Function: State::State(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
State::State(const std::string & fen)
{
    int i, enpass, position;
    std::string::const_iterator it;
    Square s;
    Color c;
    PieceType p;

    init();

    position = 0;
    for (it = fen.begin(); it < fen.end(); ++it)
    {
        if (isdigit(*it))
            position += *it - '0';
        else if (isalpha(*it))
        {
            c = isupper(*it) ? white : black;
            s = last_sq - position;
            char t = tolower(*it);
            p = t == 'p' ? pawn
              : t == 'n' ? knight
              : t == 'b' ? bishop
              : t == 'r' ? rook
              : t == 'q' ? queen
              : king;
            addPiece(c, p, s);
            mKey ^= Zobrist::key(c, p, s);
            if (p == pawn)
                mPawnKey ^= Zobrist::key(c, pawn, s);
            position++;
        }
        else if (*it == ' ')
        {
            ++it;
            break;
        }
    }
    if (*it == 'w')
    {
        mUs = white;
        mThem = black;
    }
    else
    {
        mUs = black;
        mThem = white;
        mKey ^= Zobrist::key();
    }

    enpass = -1;
    for (++it; it < fen.end(); ++it)
    {
        if (*it == 'K')
            mCastleRights += w_king_castle;
        else if (*it == 'Q')
            mCastleRights += w_queen_castle;
        else if (*it == 'k')
            mCastleRights += b_king_castle;
        else if (*it == 'q')
            mCastleRights += b_queen_castle;
        else if (isalpha(*it))
        {
            enpass = 'h' - *it;
            ++it;
            enpass += 8 * (*it - '1');
        }
    }
    mKey ^= Zobrist::key(mCastleRights);

    if (enpass > -1)
    {
        mEnPassant = square_bb[enpass];
        mKey ^= Zobrist::key(get_file(mEnPassant));
    }

    // Initialize pins.
    setPins(white);
    setPins(black);

    // Initialize checkers.
    setCheckers();

    // Initialize game phase.
    setGamePhase();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, %rbx
callq 0x16b14
movq (%r14), %r12
movq 0x8(%r14), %rax
leaq (%r12,%rax), %rbp
testq %rax, %rax
movq %rbp, (%rsp)
jle 0x16825
leaq 0x288(%rbx), %rax
movq %rax, 0x20(%rsp)
leaq 0x2e8(%rbx), %rax
movq %rax, 0x18(%rsp)
leaq 0x328(%rbx), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rbx), %r13
movq 0x20(%rbx), %rax
movq %rax, 0x8(%rsp)
xorl %r15d, %r15d
movsbl (%r12), %r14d
leal -0x30(%r14), %eax
cmpl $0x9, %eax
ja 0x166bb
addl %eax, %r15d
jmp 0x16819
movl %r14d, %edi
callq 0x4340
testl %eax, %eax
je 0x1680f
movl %r14d, %edi
callq 0x4190
movl %eax, %ebp
movl %r14d, %edi
callq 0x4310
shll $0x18, %eax
leal -0x62000000(%rax), %ecx
roll $0x7, %ecx
cmpl $0x9, %ecx
jae 0x16706
movl $0x1c1, %edx            # imm = 0x1C1
btl %ecx, %edx
jae 0x16706
movl %ecx, %eax
leaq 0x967f(%rip), %rcx      # 0x1fd80
movl (%rcx,%rax,4), %ecx
jmp 0x16713
xorl %ecx, %ecx
cmpl $0x71000000, %eax       # imm = 0x71000000
sete %cl
xorl $0x5, %ecx
movl $0x3f, %r8d
subl %r15d, %r8d
xorl %esi, %esi
testl %ebp, %ebp
sete %sil
movl %r8d, %eax
leaq 0xe2342(%rip), %r11     # 0xf8a70
movq (%r11,%rax,8), %r9
leaq (%rsi,%rsi,2), %rdx
movl %edx, %r10d
shll $0x4, %r10d
addq 0x20(%rsp), %r10
movl %ecx, %edi
orq %r9, (%r10,%rdi,8)
movq (%r11,%rax,8), %r9
orq %r9, 0x78(%rbx,%rsi,8)
movl %ecx, 0x188(%rbx,%rax,4)
movq 0x18(%rsp), %r9
leaq (%r9,%rdx,8), %r9
movslq (%r9,%rdi,4), %r10
leal 0x1(%r10), %r11d
movl %r11d, (%r9,%rdi,4)
imulq $0xf0, %rsi, %r9
addq 0x10(%rsp), %r9
leaq (%rdi,%rdi,4), %r11
leaq (%r9,%r11,8), %r9
movl %r10d, 0x88(%rbx,%rax,4)
movl %r8d, (%r9,%r10,4)
movq %rdi, %r8
shlq $0xa, %r8
movl %esi, %r9d
shll $0x8, %r9d
leaq 0x7dde(%rip), %r10      # 0x1e580
addq %r10, %r9
addq %r8, %r9
movl (%r9,%rax,4), %r8d
movl 0x200(%r9,%rax,4), %r9d
addl %r8d, 0x318(%rbx,%rsi,8)
addl %r9d, 0x31c(%rbx,%rsi,8)
shlq $0x9, %rdi
movl %edx, %esi
shll $0xa, %esi
leaq 0x14ee7c(%rip), %r8     # 0x165650
addq %r8, %rsi
addq %rdi, %rsi
xorq (%rsi,%rax,8), %r13
movq %r13, 0x18(%rbx)
xorq (%rsi,%rax,8), %r13
movq %r13, 0x18(%rbx)
testl %ecx, %ecx
jne 0x16806
shll $0xa, %edx
addq %r8, %rdx
movq 0x8(%rsp), %rcx
xorq (%rdx,%rax,8), %rcx
movq %rcx, 0x8(%rsp)
movq %rcx, 0x20(%rbx)
movq (%rsp), %rbp
incl %r15d
jmp 0x16819
cmpb $0x20, %r14b
je 0x16b0c
incq %r12
cmpq %rbp, %r12
jb 0x166a5
cmpb $0x77, (%r12)
jne 0x1683b
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, (%rbx)
jmp 0x16850
movq $0x1, (%rbx)
leaq 0x1506c7(%rip), %rax    # 0x166f10
movq (%rax), %rax
xorq %rax, 0x18(%rbx)
leaq 0x1(%r12), %r13
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpq %rbp, %r13
jae 0x168d6
movl 0xc(%rbx), %r15d
movzbl 0x1(%r12), %eax
cmpl $0x6a, %eax
jg 0x1687f
cmpl $0x4b, %eax
je 0x168be
cmpl $0x51, %eax
jne 0x1688f
addl $0x2, %r15d
jmp 0x168c7
cmpl $0x6b, %eax
je 0x168c3
cmpl $0x71, %eax
jne 0x1688f
addl $0x8, %r15d
jmp 0x168c7
movsbl %al, %ebp
movl %ebp, %edi
callq 0x4340
testl %eax, %eax
je 0x168b8
movsbl 0x2(%r12), %r14d
addq $0x2, %r12
shll $0x3, %r14d
subl %ebp, %r14d
addl $0xfffffee0, %r14d      # imm = 0xFFFFFEE0
movq %r12, %r13
movq (%rsp), %rbp
jmp 0x168cb
incl %r15d
jmp 0x168c7
addl $0x4, %r15d
movl %r15d, 0xc(%rbx)
movq %r13, %r12
incq %r13
cmpq %rbp, %r13
jb 0x16864
movslq 0xc(%rbx), %rcx
leaq 0x1505af(%rip), %rdx    # 0x166e90
movq 0x18(%rbx), %rax
xorq (%rdx,%rcx,8), %rax
movq %rax, 0x18(%rbx)
testl %r14d, %r14d
js 0x1691a
movl %r14d, %ecx
leaq 0xe2174(%rip), %rdx     # 0xf8a70
movq (%rdx,%rcx,8), %rcx
movq %rcx, 0x30(%rbx)
bsfq %rcx, %rcx
andl $0x7, %ecx
leaq 0x15053e(%rip), %rdx    # 0x166e50
xorq (%rdx,%rcx,8), %rax
movq %rax, 0x18(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x16cd6
movq %rbx, %rdi
movl $0x1, %esi
callq 0x16cd6
movl (%rbx), %ecx
movl 0x4(%rbx), %r8d
imulq $0xf0, %rcx, %rcx
movl 0x3f0(%rbx,%rcx), %esi
xorl %edi, %edi
testq %r8, %r8
sete %dil
leaq (%r8,%r8,2), %r11
movq 0x80(%rbx), %rdx
orq 0x78(%rbx), %rdx
leaq 0x4edc(%rip), %rax      # 0x1b840
movq (%rax,%rsi,8), %r13
andq %rdx, %r13
leaq 0x4cce(%rip), %rax      # 0x1b640
imulq (%rax,%rsi,8), %r13
shlq $0x4, %r11
leaq 0x4bbe(%rip), %rax      # 0x1b540
movb (%rax,%rsi,4), %cl
shrq %cl, %r13
movq 0x2a8(%rbx,%r11), %rbp
leaq 0x49a9(%rip), %r14      # 0x1b340
movq (%r14,%rsi,8), %rax
andq %rdx, %rax
leaq 0x479b(%rip), %r15      # 0x1b140
imulq (%r15,%rsi,8), %rax
leaq 0x468f(%rip), %r12      # 0x1b040
movb (%r12,%rsi,4), %cl
shrq %cl, %rax
movq 0x298(%rbx,%r11), %rcx
orq %rbp, %rcx
leaq 0xe846(%rip), %r9       # 0x25210
movq (%r9,%rsi,8), %r10
andq (%r10,%r13,8), %rcx
orq 0x2a0(%rbx,%r11), %rbp
leaq 0xea2f(%rip), %r13      # 0x25410
movq (%r13,%rsi,8), %r10
andq (%r10,%rax,8), %rbp
shll $0x9, %edi
leaq 0xe267c(%rip), %rax     # 0xf9070
addq %rax, %rdi
movq 0x288(%rbx,%r11), %r10
andq (%rdi,%rsi,8), %r10
movq 0x290(%rbx,%r11), %rdi
leaq 0x512e(%rip), %r11      # 0x1bb40
andq (%r11,%rsi,8), %rdi
orq %r10, %rdi
orq %rdi, %rcx
orq %rcx, %rbp
movq %rbp, 0x28(%rbx)
imulq $0xf0, %r8, %rcx
shlq $0x9, %r8
addq %rax, %r8
movl 0x3f0(%rbx,%rcx), %eax
movq (%r8,%rax,8), %rcx
movq %rcx, 0x38(%rbx)
movq (%r11,%rax,8), %rcx
movq %rcx, 0x40(%rbx)
leaq 0x4df1(%rip), %rcx      # 0x1b840
movq (%rcx,%rax,8), %rsi
andq %rdx, %rsi
leaq 0x4be3(%rip), %rcx      # 0x1b640
imulq (%rcx,%rax,8), %rsi
leaq 0x4ad7(%rip), %rcx      # 0x1b540
movb (%rcx,%rax,4), %cl
movq (%r9,%rax,8), %rdi
shrq %cl, %rsi
movq (%rdi,%rsi,8), %rsi
movq %rsi, 0x48(%rbx)
andq (%r14,%rax,8), %rdx
imulq (%r15,%rax,8), %rdx
movb (%r12,%rax,4), %cl
movq (%r13,%rax,8), %rax
shrq %cl, %rdx
movq (%rax,%rdx,8), %rax
movq %rax, 0x50(%rbx)
orq %rsi, %rax
movq %rax, 0x58(%rbx)
movl 0x2ec(%rbx), %eax
movl 0x310(%rbx), %ecx
addl 0x2f8(%rbx), %ecx
addl 0x304(%rbx), %eax
addl 0x2f0(%rbx), %eax
addl 0x308(%rbx), %eax
leal (%rax,%rcx,4), %eax
movl 0x30c(%rbx), %ecx
addl 0x2f4(%rbx), %ecx
leal (%rax,%rcx,2), %eax
movl $0x18, %ecx
subl %eax, %ecx
cvtsi2ss %ecx, %xmm0
mulss 0x5468(%rip), %xmm0     # 0x1bf50
addss 0x78dc(%rip), %xmm0     # 0x1e3cc
divss 0x78d8(%rip), %xmm0     # 0x1e3d0
movss %xmm0, 0x10(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incq %r12
jmp 0x16825