// File: /workspace/github_cpp_makefile_star2_O2/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 $0x18, %rsp
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
callq 0x12c96
movq (%r14), %r13
xorl %ebp, %ebp
movq %r13, %rbx
movq %r14, 0x10(%rsp)
movq 0x8(%r14), %r15
addq %r13, %r15
cmpq %r15, %rbx
jae 0x12b7e
movsbl (%rbx), %r12d
leal -0x30(%r12), %eax
cmpl $0x9, %eax
ja 0x12a9d
addl %eax, %ebp
jmp 0x12b73
movl %r12d, %edi
callq 0x4350
testl %eax, %eax
je 0x12b6d
movl %ebp, %r14d
movl %r12d, %edi
callq 0x4190
movl %eax, %r15d
xorl %ebp, %ebp
testl %eax, %eax
sete %r13b
movl %r12d, %edi
callq 0x4300
shll $0x18, %eax
leal -0x62000000(%rax), %ecx
roll $0x7, %ecx
cmpl $0x9, %ecx
jae 0x12af5
movl $0x1c1, %edx            # imm = 0x1C1
btl %ecx, %edx
jae 0x12af5
movl %ecx, %eax
leaq 0x8191(%rip), %rcx      # 0x1ac80
movl (%rcx,%rax,4), %r12d
jmp 0x12b05
xorl %r12d, %r12d
cmpl $0x71000000, %eax       # imm = 0x71000000
sete %r12b
xorl $0x5, %r12d
movb %r13b, %bpl
pushq $0x3f
popq %r13
movl %ebp, %esi
movl %r14d, %ebp
subl %r14d, %r13d
xorl %r14d, %r14d
testl %r15d, %r15d
sete %r14b
movq 0x8(%rsp), %r15
movq %r15, %rdi
movl %r12d, %edx
movl %r13d, %ecx
callq 0x13d8a
movl %r12d, %edx
movl %r13d, %eax
shlq $0x9, %rdx
imulq $0xc00, %r14, %rcx      # imm = 0xC00
addq 0x10447(%rip), %rcx     # 0x22f90
addq %rcx, %rdx
movq (%rdx,%rax,8), %rdx
xorq %rdx, 0x18(%r15)
testl %r12d, %r12d
jne 0x12b61
movq (%rcx,%rax,8), %rax
xorq %rax, 0x20(%r15)
incl %ebp
movq 0x10(%rsp), %r14
movq (%r14), %r13
jmp 0x12b73
cmpb $0x20, %r12b
je 0x12b7b
incq %rbx
jmp 0x12a78
incq %rbx
cmpb $0x77, (%rbx)
movq 0x8(%rsp), %r13
jne 0x12b92
movsd 0x6770(%rip), %xmm0     # 0x19300
jmp 0x12ba8
leaq 0x242387(%rip), %rax    # 0x254f20
movq (%rax), %rax
xorq %rax, 0x18(%r13)
movss 0x6788(%rip), %xmm0     # 0x19330
movlps %xmm0, (%r13)
movl 0xc(%r13), %r12d
pushq $-0x1
popq %r14
incq %rbx
cmpq %r15, %rbx
jae 0x12c20
movzbl (%rbx), %eax
cmpl $0x71, %eax
je 0x12bf9
cmpl $0x51, %eax
je 0x12c03
cmpl $0x6b, %eax
je 0x12c0d
cmpl $0x4b, %eax
je 0x12c17
movsbl %al, %ebp
movl %ebp, %edi
callq 0x4350
incq %rbx
testl %eax, %eax
je 0x12bb8
movsbl (%rbx), %r14d
shll $0x3, %r14d
subl %ebp, %r14d
addl $0xfffffee0, %r14d      # imm = 0xFFFFFEE0
jmp 0x12bb5
addl $0x8, %r12d
movl %r12d, 0xc(%r13)
jmp 0x12bb5
addl $0x2, %r12d
movl %r12d, 0xc(%r13)
jmp 0x12bb5
addl $0x4, %r12d
movl %r12d, 0xc(%r13)
jmp 0x12bb5
incl %r12d
movl %r12d, 0xc(%r13)
jmp 0x12bb5
movslq %r12d, %rcx
leaq 0x242276(%rip), %rdx    # 0x254ea0
movq 0x18(%r13), %rax
xorq (%rdx,%rcx,8), %rax
movq %rax, 0x18(%r13)
testl %r14d, %r14d
js 0x12c63
movl %r14d, %ecx
leaq 0x113e3b(%rip), %rdx    # 0x126a80
movq (%rdx,%rcx,8), %rcx
movq %rcx, 0x30(%r13)
bsfq %rcx, %rcx
andl $0x7, %ecx
leaq 0x242205(%rip), %rdx    # 0x254e60
xorq (%rdx,%rcx,8), %rax
movq %rax, 0x18(%r13)
movq %r13, %rdi
xorl %esi, %esi
callq 0x12db2
pushq $0x1
popq %rsi
movq %r13, %rdi
callq 0x12db2
movq %r13, %rdi
callq 0x13e48
movq %r13, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x13ed2