// File: /workspace/github_cpp_makefile_star2_O3/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 0x16a2c
movq (%r14), %r12
movq 0x8(%r14), %rax
leaq (%r12,%rax), %rbp
testq %rax, %rax
movq %rbp, (%rsp)
jle 0x16741
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 0x165d7
addl %eax, %r15d
jmp 0x16735
movl %r14d, %edi
callq 0x4340
testl %eax, %eax
je 0x1672b
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 0x16622
movl $0x1c1, %edx            # imm = 0x1C1
btl %ecx, %edx
jae 0x16622
movl %ecx, %eax
leaq 0x9673(%rip), %rcx      # 0x1fc90
movl (%rcx,%rax,4), %ecx
jmp 0x1662f
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 0xe2426(%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 0x7dd2(%rip), %r10      # 0x1e490
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 0x14ef60(%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 0x16722
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 0x16735
cmpb $0x20, %r14b
je 0x16a23
incq %r12
cmpq %rbp, %r12
jb 0x165c1
cmpb $0x77, (%r12)
jne 0x16752
movsd 0x7b80(%rip), %xmm0     # 0x1e2d0
jmp 0x16768
leaq 0x1507b7(%rip), %rax    # 0x166f10
movq (%rax), %rax
xorq %rax, 0x18(%rbx)
movss 0x7be0(%rip), %xmm0     # 0x1e348
movlps %xmm0, (%rbx)
leaq 0x1(%r12), %r13
movl 0xc(%rbx), %r15d
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpq %rbp, %r13
jae 0x167ee
movzbl 0x1(%r12), %eax
cmpl $0x6a, %eax
jg 0x1679a
cmpl $0x4b, %eax
je 0x167d9
cmpl $0x51, %eax
jne 0x167aa
addl $0x2, %r15d
jmp 0x167e2
cmpl $0x6b, %eax
je 0x167de
cmpl $0x71, %eax
jne 0x167aa
addl $0x8, %r15d
jmp 0x167e2
movsbl %al, %ebp
movl %ebp, %edi
callq 0x4340
testl %eax, %eax
je 0x167d3
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 0x167e6
incl %r15d
jmp 0x167e2
addl $0x4, %r15d
movl %r15d, 0xc(%rbx)
movq %r13, %r12
incq %r13
jmp 0x1677a
movslq %r15d, %rcx
leaq 0x150698(%rip), %rdx    # 0x166e90
movq 0x18(%rbx), %rax
xorq (%rdx,%rcx,8), %rax
movq %rax, 0x18(%rbx)
testl %r14d, %r14d
js 0x16831
movl %r14d, %ecx
leaq 0xe225d(%rip), %rdx     # 0xf8a70
movq (%rdx,%rcx,8), %rcx
movq %rcx, 0x30(%rbx)
bsfq %rcx, %rcx
andl $0x7, %ecx
leaq 0x150627(%rip), %rdx    # 0x166e50
xorq (%rdx,%rcx,8), %rax
movq %rax, 0x18(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x16bc6
movq %rbx, %rdi
movl $0x1, %esi
callq 0x16bc6
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 0x4fc5(%rip), %rax      # 0x1b840
movq (%rax,%rsi,8), %r13
andq %rdx, %r13
leaq 0x4db7(%rip), %rax      # 0x1b640
imulq (%rax,%rsi,8), %r13
shlq $0x4, %r11
leaq 0x4ca7(%rip), %rax      # 0x1b540
movb (%rax,%rsi,4), %cl
shrq %cl, %r13
movq 0x2a8(%rbx,%r11), %rbp
leaq 0x4a92(%rip), %r14      # 0x1b340
movq (%r14,%rsi,8), %rax
andq %rdx, %rax
leaq 0x4884(%rip), %r15      # 0x1b140
imulq (%r15,%rsi,8), %rax
leaq 0x4778(%rip), %r12      # 0x1b040
movb (%r12,%rsi,4), %cl
shrq %cl, %rax
movq 0x298(%rbx,%r11), %rcx
orq %rbp, %rcx
leaq 0xe92f(%rip), %r9       # 0x25210
movq (%r9,%rsi,8), %r10
andq (%r10,%r13,8), %rcx
orq 0x2a0(%rbx,%r11), %rbp
leaq 0xeb18(%rip), %r13      # 0x25410
movq (%r13,%rsi,8), %r10
andq (%r10,%rax,8), %rbp
shll $0x9, %edi
leaq 0xe2765(%rip), %rax     # 0xf9070
addq %rax, %rdi
movq 0x288(%rbx,%r11), %r10
andq (%rdi,%rsi,8), %r10
movq 0x290(%rbx,%r11), %rdi
leaq 0x5117(%rip), %r11      # 0x1ba40
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 0x4eda(%rip), %rcx      # 0x1b840
movq (%rcx,%rax,8), %rsi
andq %rdx, %rsi
leaq 0x4ccc(%rip), %rcx      # 0x1b640
imulq (%rcx,%rax,8), %rsi
leaq 0x4bc0(%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 0x5451(%rip), %xmm0     # 0x1be50
addss 0x7939(%rip), %xmm0     # 0x1e340
divss 0x7935(%rip), %xmm0     # 0x1e344
movss %xmm0, 0x10(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incq %r12
jmp 0x16741
nop