// File: 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:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x397e0
movq 0x18(%rsp), %rdi
callq 0x369a0
movl $0x0, 0x5c(%rsp)
movq 0x68(%rsp), %rdi
callq 0x5260
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x68(%rsp), %rdi
callq 0x54e0
movq %rax, 0x30(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x39800
testb $0x1, %al
jne 0x365c4
jmp 0x36787
leaq 0x50(%rsp), %rdi
callq 0x39840
movsbl (%rax), %edi
callq 0x5230
cmpl $0x0, %eax
je 0x365f8
leaq 0x50(%rsp), %rdi
callq 0x39840
movsbl (%rax), %eax
subl $0x30, %eax
addl 0x5c(%rsp), %eax
movl %eax, 0x5c(%rsp)
jmp 0x36776
leaq 0x50(%rsp), %rdi
callq 0x39840
movsbl (%rax), %edi
callq 0x5420
cmpl $0x0, %eax
je 0x36754
leaq 0x50(%rsp), %rdi
callq 0x39840
movsbl (%rax), %edi
callq 0x51c0
movl %eax, %edx
movl $0x1, %eax
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, 0x48(%rsp)
movl 0x5c(%rsp), %esi
movl $0x3f, %edi
callq 0x24e80
movl %eax, 0x4c(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x39840
movsbl (%rax), %edi
callq 0x53c0
movb %al, 0x2f(%rsp)
movsbl 0x2f(%rsp), %eax
cmpl $0x70, %eax
jne 0x36672
xorl %eax, %eax
movl %eax, 0x14(%rsp)
jmp 0x366e2
movsbl 0x2f(%rsp), %eax
cmpl $0x6e, %eax
jne 0x36687
movl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x366da
movsbl 0x2f(%rsp), %eax
cmpl $0x62, %eax
jne 0x3669c
movl $0x2, %eax
movl %eax, 0xc(%rsp)
jmp 0x366d2
movsbl 0x2f(%rsp), %eax
cmpl $0x72, %eax
jne 0x366b1
movl $0x3, %eax
movl %eax, 0x8(%rsp)
jmp 0x366ca
movsbl 0x2f(%rsp), %edx
movl $0x5, %eax
movl $0x4, %ecx
cmpl $0x71, %edx
cmovel %ecx, %eax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x14(%rsp)
movq 0x18(%rsp), %rdi
movl 0x14(%rsp), %eax
movl %eax, 0x44(%rsp)
movl 0x48(%rsp), %esi
movl 0x44(%rsp), %edx
movl 0x4c(%rsp), %ecx
callq 0x39850
movl 0x48(%rsp), %edi
movl 0x44(%rsp), %esi
movl 0x4c(%rsp), %edx
callq 0x39a70
movq %rax, %rcx
movq 0x18(%rsp), %rax
xorq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
cmpl $0x0, 0x44(%rsp)
jne 0x36747
movl 0x48(%rsp), %edi
movl 0x4c(%rsp), %edx
xorl %esi, %esi
callq 0x39a70
movq %rax, %rcx
movq 0x18(%rsp), %rax
xorq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x36774
leaq 0x50(%rsp), %rdi
callq 0x39840
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x36772
leaq 0x50(%rsp), %rdi
callq 0x39ab0
jmp 0x36787
jmp 0x36774
jmp 0x36776
jmp 0x36778
leaq 0x50(%rsp), %rdi
callq 0x39ab0
jmp 0x3659d
leaq 0x50(%rsp), %rdi
callq 0x39840
movsbl (%rax), %eax
cmpl $0x77, %eax
jne 0x367ad
movq 0x18(%rsp), %rax
movl $0x0, (%rax)
movl $0x1, 0x4(%rax)
jmp 0x367d4
movq 0x18(%rsp), %rax
movl $0x1, (%rax)
movl $0x0, 0x4(%rax)
callq 0x39ad0
movq %rax, %rcx
movq 0x18(%rsp), %rax
xorq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movl $0xffffffff, 0x60(%rsp) # imm = 0xFFFFFFFF
leaq 0x50(%rsp), %rdi
callq 0x39ab0
movq 0x68(%rsp), %rdi
callq 0x54e0
movq %rax, 0x20(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x39800
testb $0x1, %al
jne 0x3680d
jmp 0x36908
leaq 0x50(%rsp), %rdi
callq 0x39840
movsbl (%rax), %eax
cmpl $0x4b, %eax
jne 0x36832
movq 0x18(%rsp), %rax
movl 0xc(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rax)
jmp 0x368f7
leaq 0x50(%rsp), %rdi
callq 0x39840
movsbl (%rax), %eax
cmpl $0x51, %eax
jne 0x36857
movq 0x18(%rsp), %rax
movl 0xc(%rax), %ecx
addl $0x2, %ecx
movl %ecx, 0xc(%rax)
jmp 0x368f5
leaq 0x50(%rsp), %rdi
callq 0x39840
movsbl (%rax), %eax
cmpl $0x6b, %eax
jne 0x36879
movq 0x18(%rsp), %rax
movl 0xc(%rax), %ecx
addl $0x4, %ecx
movl %ecx, 0xc(%rax)
jmp 0x368f3
leaq 0x50(%rsp), %rdi
callq 0x39840
movsbl (%rax), %eax
cmpl $0x71, %eax
jne 0x3689b
movq 0x18(%rsp), %rax
movl 0xc(%rax), %ecx
addl $0x8, %ecx
movl %ecx, 0xc(%rax)
jmp 0x368f1
leaq 0x50(%rsp), %rdi
callq 0x39840
movsbl (%rax), %edi
callq 0x5420
cmpl $0x0, %eax
je 0x368ef
leaq 0x50(%rsp), %rdi
callq 0x39840
movsbl (%rax), %ecx
movl $0x68, %eax
subl %ecx, %eax
movl %eax, 0x60(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x39ab0
leaq 0x50(%rsp), %rdi
callq 0x39840
movsbl (%rax), %eax
subl $0x31, %eax
shll $0x3, %eax
addl 0x60(%rsp), %eax
movl %eax, 0x60(%rsp)
jmp 0x368f1
jmp 0x368f3
jmp 0x368f5
jmp 0x368f7
jmp 0x368f9
leaq 0x50(%rsp), %rdi
callq 0x39ab0
jmp 0x367e6
movq 0x18(%rsp), %rax
movl 0xc(%rax), %edi
callq 0x39ae0
movq %rax, %rcx
movq 0x18(%rsp), %rax
xorq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
cmpl $-0x1, 0x60(%rsp)
jle 0x36965
movq 0x18(%rsp), %rax
movslq 0x60(%rsp), %rdx
leaq 0x11e1d3(%rip), %rcx    # 0x154b10
movq (%rcx,%rdx,8), %rcx
movq %rcx, 0x30(%rax)
movq 0x30(%rax), %rdi
callq 0x39b20
movl %eax, %edi
callq 0x39b00
movq %rax, %rcx
movq 0x18(%rsp), %rax
xorq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x36bf0
movq 0x18(%rsp), %rdi
movl $0x1, %esi
callq 0x36bf0
movq 0x18(%rsp), %rdi
callq 0x39b40
movq 0x18(%rsp), %rdi
callq 0x39cc0
addq $0x78, %rsp
retq
nopl (%rax)