// File: /workspace/github_cpp_makefile_star2_O2/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 -0xa8(%rbp), %r15
movq %r15, %rdi
callq 0x2200
movq %rbx, %rdi
movq %r15, %rsi
callq 0x37c4
testb %al, %al
je 0x3690
leaq -0xa8(%rbp), %rdi
callq 0x2308
leaq -0x228(%rbp), %r15
pushq $0x8
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x2260
leaq -0x70(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x80(%rbp), %rsi
movq %r15, %rdi
callq 0x21e0
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rsi
addq %rdi, %rsi
leaq -0x30(%rbp), %rdx
movb $0x2f, (%rdx)
callq 0x59e7
leaq -0x80(%rbp), %rdi
movq (%rdi), %rdx
addq 0x8(%rdi), %rdx
movq %rax, %rsi
callq 0x2040
leaq 0x8(%rbx), %rax
movq %rax, -0x38(%rbp)
leaq 0x18(%rbx), %rax
movq %rax, -0x60(%rbp)
leaq 0x20(%rbx), %rax
movq %rax, -0x58(%rbp)
leaq 0x28(%rbx), %rax
movq %rax, -0x50(%rbp)
leaq 0x30(%rbx), %rax
movq %rax, -0x48(%rbp)
leaq 0x38(%rbx), %rax
movq %rax, -0x40(%rbp)
leaq 0x10(%rbx), %rax
movq %rax, -0x88(%rbp)
xorl %r15d, %r15d
pushq $0x1
popq %r13
xorl %r14d, %r14d
cmpq %r15, -0x78(%rbp)
jbe 0x356e
movq -0x80(%rbp), %rax
movb (%rax,%r15), %r12b
movsbl %r12b, %edi
leal -0x30(%rdi), %eax
cmpl $0x9, %eax
ja 0x344a
addl %eax, %r14d
jmp 0x3566
callq 0x2240
testl %eax, %eax
je 0x3566
leal -0x41(%r12), %eax
cmpb $0x19, %al
ja 0x3476
movq %rbx, %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0x3062
movq -0x80(%rbp), %rax
movb (%rax,%r15), %r12b
leal -0x61(%r12), %eax
cmpb $0x19, %al
ja 0x3496
movq -0x38(%rbp), %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0x3062
movq -0x80(%rbp), %rax
movb (%rax,%r15), %r12b
movzbl %r12b, %eax
orl $0x20, %eax
cmpl $0x6e, %eax
jne 0x34b9
movq -0x60(%rbp), %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0x3062
movq -0x80(%rbp), %rax
movb (%rax,%r15), %r12b
movzbl %r12b, %eax
orl $0x20, %eax
cmpl $0x62, %eax
jne 0x34dc
movq -0x58(%rbp), %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0x3062
movq -0x80(%rbp), %rax
movb (%rax,%r15), %r12b
movzbl %r12b, %eax
orl $0x20, %eax
cmpl $0x72, %eax
jne 0x34ff
movq -0x50(%rbp), %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0x3062
movq -0x80(%rbp), %rax
movb (%rax,%r15), %r12b
movzbl %r12b, %eax
orl $0x20, %eax
cmpl $0x71, %eax
jne 0x3522
movq -0x48(%rbp), %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0x3062
movq -0x80(%rbp), %rax
movb (%rax,%r15), %r12b
movzbl %r12b, %eax
orl $0x20, %eax
cmpl $0x6b, %eax
jne 0x3545
movq -0x40(%rbp), %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0x3062
movq -0x80(%rbp), %rax
movb (%rax,%r15), %r12b
movzbl %r12b, %eax
orl $0x20, %eax
cmpl $0x70, %eax
jne 0x3563
movq -0x88(%rbp), %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0x3062
incl %r14d
incq %r15
jmp 0x3424
movq -0x60(%rbp), %rdi
callq 0x3154
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x3036
movq -0x30(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rax, (%rcx)
movq -0x58(%rbp), %rdi
callq 0x3154
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x3036
movq -0x30(%rbp), %rax
movq -0x58(%rbp), %rcx
movq %rax, (%rcx)
movq -0x50(%rbp), %rdi
callq 0x3154
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x3036
movq -0x30(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rax, (%rcx)
movq -0x48(%rbp), %rdi
callq 0x3154
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x3036
movq -0x30(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rax, (%rcx)
movq -0x40(%rbp), %rdi
callq 0x3154
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x3036
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rax, (%rcx)
movq -0x88(%rbp), %rdi
callq 0x3154
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x3036
movq -0x30(%rbp), %rax
movq %rax, 0x10(%rbx)
movq %rbx, %rdi
callq 0x3154
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x3036
movq -0x30(%rbp), %rax
movq %rax, (%rbx)
movq -0x38(%rbp), %rdi
callq 0x3154
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x3036
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rax, (%rcx)
leaq -0x80(%rbp), %rdi
callq 0x2308
leaq -0x228(%rbp), %rdi
callq 0x20b0
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x505f(%rip), %rdi      # 0x86f6
leaq 0x4eb1(%rip), %rsi      # 0x854f
leaq 0x5061(%rip), %rcx      # 0x8706
movl $0xa6, %edx
callq 0x2100
jmp 0x36d6
jmp 0x36d6
jmp 0x36d6
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x2308
jmp 0x36ee
jmp 0x36d6
jmp 0x36d6
jmp 0x36d6
jmp 0x36d6
jmp 0x36d6
jmp 0x36d6
jmp 0x36d6
jmp 0x36d6
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x2308
leaq -0x228(%rbp), %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x2290