// File: /workspace/github_cpp_makefile_star2_O1/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 $0x1f8, %rsp            # imm = 0x1F8
movq %rsi, %r14
movq %rdi, %rbx
leaq -0x90(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%rsi), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0xa0(%rbp), %r15
movq %r15, %rdi
callq 0x6722
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3e70
testb %al, %al
je 0x3ba9
movq -0xa0(%rbp), %rdi
cmpq %r12, %rdi
je 0x3899
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2150
leaq -0x220(%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 0x67bb
movq %rax, %rcx
subq -0x50(%rbp), %rcx
movq %rcx, -0x48(%rbp)
movb $0x0, (%rax)
cmpq $0x0, -0x48(%rbp)
je 0x3a77
leaq 0x8(%rbx), %rax
movq %rax, -0x58(%rbp)
leaq 0x18(%rbx), %rax
movq %rax, -0x80(%rbp)
leaq 0x20(%rbx), %rax
movq %rax, -0x78(%rbp)
leaq 0x28(%rbx), %rax
movq %rax, -0x70(%rbp)
leaq 0x30(%rbx), %rax
movq %rax, -0x68(%rbp)
leaq 0x38(%rbx), %rax
movq %rax, -0x60(%rbp)
leaq 0x10(%rbx), %r12
xorl %r15d, %r15d
xorl %r13d, %r13d
movq -0x50(%rbp), %rax
movsbl (%rax,%r15), %r14d
leal -0x30(%r14), %eax
cmpl $0x9, %eax
ja 0x3953
addl %eax, %r13d
jmp 0x3a6a
movl %r14d, %edi
callq 0x2220
testl %eax, %eax
je 0x3a6a
addb $-0x41, %r14b
cmpb $0x19, %r14b
ja 0x397d
movq %rbx, %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x3376
movq -0x50(%rbp), %rax
movb (%rax,%r15), %al
addb $-0x61, %al
cmpb $0x19, %al
ja 0x399c
movq -0x58(%rbp), %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x3376
movq -0x50(%rbp), %rax
movzbl (%rax,%r15), %eax
orl $0x20, %eax
cmpl $0x6e, %eax
jne 0x39be
movq -0x80(%rbp), %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x3376
movq -0x50(%rbp), %rax
movzbl (%rax,%r15), %eax
orl $0x20, %eax
cmpl $0x62, %eax
jne 0x39e0
movq -0x78(%rbp), %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x3376
movq -0x50(%rbp), %rax
movzbl (%rax,%r15), %eax
orl $0x20, %eax
cmpl $0x72, %eax
jne 0x3a02
movq -0x70(%rbp), %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x3376
movq -0x50(%rbp), %rax
movzbl (%rax,%r15), %eax
orl $0x20, %eax
cmpl $0x71, %eax
jne 0x3a24
movq -0x68(%rbp), %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x3376
movq -0x50(%rbp), %rax
movzbl (%rax,%r15), %eax
orl $0x20, %eax
cmpl $0x6b, %eax
jne 0x3a46
movq -0x60(%rbp), %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x3376
movq -0x50(%rbp), %rax
movzbl (%rax,%r15), %eax
orl $0x20, %eax
cmpl $0x70, %eax
jne 0x3a67
movq %r12, %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x3376
incl %r13d
incq %r15
cmpq %r15, -0x48(%rbp)
ja 0x3939
leaq 0x18(%rbx), %rdi
callq 0x3472
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x334a
movq -0x30(%rbp), %rax
movq %rax, 0x18(%rbx)
leaq 0x20(%rbx), %rdi
callq 0x3472
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x334a
movq -0x30(%rbp), %rax
movq %rax, 0x20(%rbx)
leaq 0x28(%rbx), %rdi
callq 0x3472
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x334a
movq -0x30(%rbp), %rax
movq %rax, 0x28(%rbx)
leaq 0x30(%rbx), %rdi
callq 0x3472
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x334a
movq -0x30(%rbp), %rax
movq %rax, 0x30(%rbx)
leaq 0x38(%rbx), %rdi
callq 0x3472
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x334a
movq -0x30(%rbp), %rax
movq %rax, 0x38(%rbx)
leaq 0x10(%rbx), %rdi
callq 0x3472
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x334a
movq -0x30(%rbp), %rax
movq %rax, 0x10(%rbx)
movq %rbx, %rdi
callq 0x3472
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x334a
movq -0x30(%rbp), %rax
movq %rax, (%rbx)
addq $0x8, %rbx
movq %rbx, %rdi
callq 0x3472
leaq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x334a
movq -0x30(%rbp), %rax
movq %rax, (%rbx)
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3b78
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2150
movq 0x9451(%rip), %rsi      # 0xcfd0
leaq -0x220(%rbp), %rdi
callq 0x21d0
leaq -0x1a8(%rbp), %rdi
callq 0x2070
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5b26(%rip), %rdi      # 0x96d6
leaq 0x5978(%rip), %rsi      # 0x952f
leaq 0x5b28(%rip), %rcx      # 0x96e6
movl $0xa6, %edx
callq 0x20c0
jmp 0x3bfc
jmp 0x3bfc
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
cmpq %r12, %rdi
je 0x3c37
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2150
jmp 0x3c37
jmp 0x3bfc
jmp 0x3bfc
jmp 0x3bfc
jmp 0x3bfc
jmp 0x3bfc
jmp 0x3bfc
jmp 0x3bfc
jmp 0x3bfc
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3c18
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2150
movq 0x93b1(%rip), %rsi      # 0xcfd0
leaq -0x220(%rbp), %rdi
callq 0x21d0
leaq -0x1a8(%rbp), %rdi
callq 0x2070
movq %rbx, %rdi
callq 0x2270
nop