// File: /workspace/github_cpp_makefile_star2_O3/niekh1234[P]nnchesslib/board.cpp
// Function: nnchesslib::ChessBoard::generateBitBoards(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void ChessBoard::generateBitBoards(std::string fen)
{
    assert(isValidFen(fen));

    std::istringstream iss(fen);
    std::string board;
    // getting the board (first) part of the fen string.
    iss >> board;

    // removing all the '/' from the board string.
    board.erase(std::remove(board.begin(), board.end(), '/'), board.end());

    // the idea is to increment bitIndex by 1 if a letter is occuring in the board string.
    // and to increment it by however much the number says when it is not a letter.
    int bitIndex = 0;
    for(int i = 0; i < board.size(); i++)
    {
        if(isdigit(board[i]))
            bitIndex += (int(board[i]) - 48);

        else if (isalpha(board[i]))
        {
            // Generate bitboard for white and black
            // this is reversed atm.
            if (board[i] >= 'A' && board[i] <= 'Z') boardinfo.whitePieces.set(bitIndex, true);
            if (board[i] >= 'a' && board[i] <= 'z') boardinfo.blackPieces.set(bitIndex, true);

            // Generate bitboard for pieces
            if (board[i] == 'N' || board[i] == 'n') boardinfo.knights.set(bitIndex, true);
            if (board[i] == 'B' || board[i] == 'b') boardinfo.bishops.set(bitIndex, true);
            if (board[i] == 'R' || board[i] == 'r') boardinfo.rooks.set(bitIndex, true);
            if (board[i] == 'Q' || board[i] == 'q') boardinfo.queens.set(bitIndex, true);
            if (board[i] == 'K' || board[i] == 'k') boardinfo.kings.set(bitIndex, true);
            if (board[i] == 'P' || board[i] == 'p') boardinfo.pawns.set(bitIndex, true);

            bitIndex += 1;
        }
    }
    // cannot think of another way to do this yet.
    // The problem is that the code above generates the board but mirrorred vertically.
    boardinfo.knights = boardinfo.knights.flipVertical();
    boardinfo.bishops = boardinfo.bishops.flipVertical();
    boardinfo.rooks = boardinfo.rooks.flipVertical();
    boardinfo.queens = boardinfo.queens.flipVertical();
    boardinfo.kings = boardinfo.kings.flipVertical();
    boardinfo.pawns = boardinfo.pawns.flipVertical();
    boardinfo.whitePieces = boardinfo.whitePieces.flipVertical();
    boardinfo.blackPieces = boardinfo.blackPieces.flipVertical();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rsi, %r14
movq %rdi, %rbx
leaq -0x98(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%rsi), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0xa8(%rbp), %r15
movq %r15, %rdi
callq 0x671c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3ecc
testb %al, %al
je 0x3c06
movq -0xa8(%rbp), %rdi
cmpq %r12, %rdi
je 0x38d5
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2150
leaq -0x228(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
movl $0x8, %edx
callq 0x2250
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x50(%rbp), %rsi
movq %r15, %rdi
callq 0x21b0
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
addq %rdi, %rsi
leaq -0x30(%rbp), %rdx
movb $0x2f, (%rdx)
callq 0x67ba
movq %rax, %rcx
subq -0x50(%rbp), %rcx
movq %rcx, -0x48(%rbp)
movb $0x0, (%rax)
movq -0x48(%rbp), %r12
testq %r12, %r12
je 0x3ad4
leaq 0x8(%rbx), %rax
movq %rax, -0x58(%rbp)
leaq 0x18(%rbx), %rax
movq %rax, -0x88(%rbp)
leaq 0x20(%rbx), %rax
movq %rax, -0x80(%rbp)
leaq 0x28(%rbx), %rax
movq %rax, -0x78(%rbp)
leaq 0x30(%rbx), %rax
movq %rax, -0x70(%rbp)
leaq 0x38(%rbx), %rax
movq %rax, -0x68(%rbp)
leaq 0x10(%rbx), %rax
movq %rax, -0x60(%rbp)
xorl %r14d, %r14d
xorl %r13d, %r13d
movq -0x50(%rbp), %rax
movb (%rax,%r14), %r15b
movsbl %r15b, %edi
leal -0x30(%rdi), %eax
cmpl $0x9, %eax
ja 0x399a
addl %eax, %r13d
jmp 0x3ac8
callq 0x2220
testl %eax, %eax
je 0x3ac8
leal -0x41(%r15), %eax
cmpb $0x19, %al
ja 0x39c7
movq %rbx, %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x33b2
movq -0x50(%rbp), %rax
movb (%rax,%r14), %r15b
leal -0x61(%r15), %eax
cmpb $0x19, %al
ja 0x39e8
movq -0x58(%rbp), %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x33b2
movq -0x50(%rbp), %rax
movb (%rax,%r14), %r15b
movzbl %r15b, %eax
orl $0x20, %eax
cmpl $0x6e, %eax
jne 0x3a10
movq -0x88(%rbp), %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x33b2
movq -0x50(%rbp), %rax
movb (%rax,%r14), %r15b
movzbl %r15b, %eax
orl $0x20, %eax
cmpl $0x62, %eax
jne 0x3a35
movq -0x80(%rbp), %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x33b2
movq -0x50(%rbp), %rax
movb (%rax,%r14), %r15b
movzbl %r15b, %eax
orl $0x20, %eax
cmpl $0x72, %eax
jne 0x3a5a
movq -0x78(%rbp), %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x33b2
movq -0x50(%rbp), %rax
movb (%rax,%r14), %r15b
movzbl %r15b, %eax
orl $0x20, %eax
cmpl $0x71, %eax
jne 0x3a7f
movq -0x70(%rbp), %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x33b2
movq -0x50(%rbp), %rax
movb (%rax,%r14), %r15b
movzbl %r15b, %eax
orl $0x20, %eax
cmpl $0x6b, %eax
jne 0x3aa4
movq -0x68(%rbp), %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x33b2
movq -0x50(%rbp), %rax
movb (%rax,%r14), %r15b
movzbl %r15b, %eax
orl $0x20, %eax
cmpl $0x70, %eax
jne 0x3ac1
movq -0x60(%rbp), %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x33b2
incl %r13d
movq -0x48(%rbp), %r12
incq %r14
cmpq %r14, %r12
ja 0x397e
leaq 0x18(%rbx), %rdi
callq 0x34ae
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x3386
movq -0x30(%rbp), %rax
movq %rax, 0x18(%rbx)
leaq 0x20(%rbx), %rdi
callq 0x34ae
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x3386
movq -0x30(%rbp), %rax
movq %rax, 0x20(%rbx)
leaq 0x28(%rbx), %rdi
callq 0x34ae
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x3386
movq -0x30(%rbp), %rax
movq %rax, 0x28(%rbx)
leaq 0x30(%rbx), %rdi
callq 0x34ae
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x3386
movq -0x30(%rbp), %rax
movq %rax, 0x30(%rbx)
leaq 0x38(%rbx), %rdi
callq 0x34ae
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x3386
movq -0x30(%rbp), %rax
movq %rax, 0x38(%rbx)
leaq 0x10(%rbx), %rdi
callq 0x34ae
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x3386
movq -0x30(%rbp), %rax
movq %rax, 0x10(%rbx)
movq %rbx, %rdi
callq 0x34ae
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x3386
movq -0x30(%rbp), %rax
movq %rax, (%rbx)
addq $0x8, %rbx
movq %rbx, %rdi
callq 0x34ae
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x3386
movq -0x30(%rbp), %rax
movq %rax, (%rbx)
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3bd5
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2150
movq 0x93f4(%rip), %rsi      # 0xcfd0
leaq -0x228(%rbp), %rdi
callq 0x21d0
leaq -0x1b0(%rbp), %rdi
callq 0x2070
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5ac9(%rip), %rdi      # 0x96d6
leaq 0x591b(%rip), %rsi      # 0x952f
leaq 0x5acb(%rip), %rcx      # 0x96e6
movl $0xa6, %edx
callq 0x20c0
jmp 0x3c59
jmp 0x3c59
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
cmpq %r12, %rdi
je 0x3c94
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2150
jmp 0x3c94
jmp 0x3c59
jmp 0x3c59
jmp 0x3c59
jmp 0x3c59
jmp 0x3c59
jmp 0x3c59
jmp 0x3c59
jmp 0x3c59
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3c75
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2150
movq 0x9354(%rip), %rsi      # 0xcfd0
leaq -0x228(%rbp), %rdi
callq 0x21d0
leaq -0x1b0(%rbp), %rdi
callq 0x2070
movq %rbx, %rdi
callq 0x2270