// File: 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
subq $0x3a0, %rsp            # imm = 0x3A0
movq %rsi, -0x288(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x280(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x278(%rbp)
callq 0x30d0
movq -0x280(%rbp), %rdi
movq -0x278(%rbp), %rsi
callq 0x5dc0
movb %al, -0x269(%rbp)
jmp 0x5440
movb -0x269(%rbp), %al
testb $0x1, %al
jne 0x544c
jmp 0x544e
jmp 0x5487
leaq 0x9401(%rip), %rdi      # 0xe856
leaq 0x9173(%rip), %rsi      # 0xe5cf
movl $0xa6, %edx
leaq 0x93fe(%rip), %rcx      # 0xe866
callq 0x3150
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x34a8
jmp 0x5c6b
leaq -0x30(%rbp), %rdi
callq 0x34a8
movq -0x288(%rbp), %rsi
leaq -0x1c0(%rbp), %rdi
movq %rdi, -0x298(%rbp)
movl $0x8, %edx
callq 0x33e0
leaq -0x1e0(%rbp), %rdi
movq %rdi, -0x290(%rbp)
callq 0x3350
movq -0x298(%rbp), %rdi
movq -0x290(%rbp), %rsi
callq 0x3320
jmp 0x54d7
leaq -0x1e0(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x3200
movq -0x2a8(%rbp), %rdi
movq %rax, -0x1f8(%rbp)
callq 0x3120
movq %rax, -0x200(%rbp)
movb $0x2f, -0x201(%rbp)
movq -0x1f8(%rbp), %rdi
movq -0x200(%rbp), %rsi
leaq -0x201(%rbp), %rdx
callq 0x9b80
movq %rax, -0x2a0(%rbp)
jmp 0x552e
movq -0x2a0(%rbp), %rax
movq %rax, -0x1f0(%rbp)
leaq -0x1e8(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
callq 0x9bd0
leaq -0x1e0(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x3120
movq %rax, -0x218(%rbp)
leaq -0x210(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x9bd0
movq -0x2b8(%rbp), %rdi
movq -0x1e8(%rbp), %rsi
movq -0x210(%rbp), %rdx
callq 0x3060
movq %rax, -0x2b0(%rbp)
jmp 0x559f
movq -0x2b0(%rbp), %rax
movq %rax, -0x220(%rbp)
movl $0x0, -0x224(%rbp)
movl $0x0, -0x228(%rbp)
movslq -0x228(%rbp), %rax
movq %rax, -0x2c0(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x3180
movq %rax, %rcx
movq -0x2c0(%rbp), %rax
cmpq %rcx, %rax
jae 0x5a80
movslq -0x228(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x3480
movq %rax, -0x2c8(%rbp)
jmp 0x560a
movq -0x2c8(%rbp), %rax
movsbl (%rax), %edi
callq 0x3230
cmpl $0x0, %eax
je 0x5681
movslq -0x228(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x3480
movq %rax, -0x2d0(%rbp)
jmp 0x563a
movq -0x2d0(%rbp), %rax
movsbl (%rax), %eax
subl $0x30, %eax
addl -0x224(%rbp), %eax
movl %eax, -0x224(%rbp)
jmp 0x5a6a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x34a8
leaq -0x1c0(%rbp), %rdi
callq 0x3100
jmp 0x5c6b
movslq -0x228(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x3480
movq %rax, -0x2d8(%rbp)
jmp 0x569d
movq -0x2d8(%rbp), %rax
movsbl (%rax), %edi
callq 0x33b0
cmpl $0x0, %eax
je 0x5a68
movslq -0x228(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x3480
movq %rax, -0x2e0(%rbp)
jmp 0x56d1
movq -0x2e0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x41, %eax
jl 0x5726
movslq -0x228(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x3480
movq %rax, -0x2e8(%rbp)
jmp 0x56fc
movq -0x2e8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5a, %eax
jg 0x5726
movq -0x280(%rbp), %rdi
movl -0x224(%rbp), %esi
movl $0x1, %edx
callq 0x4c40
jmp 0x5724
jmp 0x5726
movslq -0x228(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x3480
movq %rax, -0x2f0(%rbp)
jmp 0x5742
movq -0x2f0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x61, %eax
jl 0x579b
movslq -0x228(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x3480
movq %rax, -0x2f8(%rbp)
jmp 0x576d
movq -0x2f8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7a, %eax
jg 0x579b
movq -0x280(%rbp), %rdi
addq $0x8, %rdi
movl -0x224(%rbp), %esi
movl $0x1, %edx
callq 0x4c40
jmp 0x5799
jmp 0x579b
movslq -0x228(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x3480
movq %rax, -0x300(%rbp)
jmp 0x57b7
movq -0x300(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x4e, %eax
je 0x57f1
movslq -0x228(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x3480
movq %rax, -0x308(%rbp)
jmp 0x57e2
movq -0x308(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x6e, %eax
jne 0x5810
movq -0x280(%rbp), %rdi
addq $0x18, %rdi
movl -0x224(%rbp), %esi
movl $0x1, %edx
callq 0x4c40
jmp 0x580e
jmp 0x5810
movslq -0x228(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x3480
movq %rax, -0x310(%rbp)
jmp 0x582c
movq -0x310(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x42, %eax
je 0x5866
movslq -0x228(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x3480
movq %rax, -0x318(%rbp)
jmp 0x5857
movq -0x318(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x62, %eax
jne 0x5885
movq -0x280(%rbp), %rdi
addq $0x20, %rdi
movl -0x224(%rbp), %esi
movl $0x1, %edx
callq 0x4c40
jmp 0x5883
jmp 0x5885
movslq -0x228(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x3480
movq %rax, -0x320(%rbp)
jmp 0x58a1
movq -0x320(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x52, %eax
je 0x58db
movslq -0x228(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x3480
movq %rax, -0x328(%rbp)
jmp 0x58cc
movq -0x328(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x72, %eax
jne 0x58fa
movq -0x280(%rbp), %rdi
addq $0x28, %rdi
movl -0x224(%rbp), %esi
movl $0x1, %edx
callq 0x4c40
jmp 0x58f8
jmp 0x58fa
movslq -0x228(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x3480
movq %rax, -0x330(%rbp)
jmp 0x5916
movq -0x330(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x51, %eax
je 0x5950
movslq -0x228(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x3480
movq %rax, -0x338(%rbp)
jmp 0x5941
movq -0x338(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x71, %eax
jne 0x596f
movq -0x280(%rbp), %rdi
addq $0x30, %rdi
movl -0x224(%rbp), %esi
movl $0x1, %edx
callq 0x4c40
jmp 0x596d
jmp 0x596f
movslq -0x228(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x3480
movq %rax, -0x340(%rbp)
jmp 0x598b
movq -0x340(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x4b, %eax
je 0x59c5
movslq -0x228(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x3480
movq %rax, -0x348(%rbp)
jmp 0x59b6
movq -0x348(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x6b, %eax
jne 0x59e4
movq -0x280(%rbp), %rdi
addq $0x38, %rdi
movl -0x224(%rbp), %esi
movl $0x1, %edx
callq 0x4c40
jmp 0x59e2
jmp 0x59e4
movslq -0x228(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x3480
movq %rax, -0x350(%rbp)
jmp 0x5a00
movq -0x350(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x50, %eax
je 0x5a3a
movslq -0x228(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x3480
movq %rax, -0x358(%rbp)
jmp 0x5a2b
movq -0x358(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x70, %eax
jne 0x5a59
movq -0x280(%rbp), %rdi
addq $0x10, %rdi
movl -0x224(%rbp), %esi
movl $0x1, %edx
callq 0x4c40
jmp 0x5a57
jmp 0x5a59
movl -0x224(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x224(%rbp)
jmp 0x5a6a
jmp 0x5a6c
movl -0x228(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x228(%rbp)
jmp 0x55c1
movq -0x280(%rbp), %rdi
addq $0x18, %rdi
callq 0x4e90
movq %rax, -0x360(%rbp)
jmp 0x5a99
movq -0x360(%rbp), %rsi
leaq -0x230(%rbp), %rdi
callq 0x4bc0
jmp 0x5aae
movq -0x280(%rbp), %rdi
movq -0x230(%rbp), %rax
movq %rax, 0x18(%rdi)
addq $0x20, %rdi
callq 0x4e90
movq %rax, -0x368(%rbp)
jmp 0x5ad2
movq -0x368(%rbp), %rsi
leaq -0x238(%rbp), %rdi
callq 0x4bc0
jmp 0x5ae7
movq -0x280(%rbp), %rdi
movq -0x238(%rbp), %rax
movq %rax, 0x20(%rdi)
addq $0x28, %rdi
callq 0x4e90
movq %rax, -0x370(%rbp)
jmp 0x5b0b
movq -0x370(%rbp), %rsi
leaq -0x240(%rbp), %rdi
callq 0x4bc0
jmp 0x5b20
movq -0x280(%rbp), %rdi
movq -0x240(%rbp), %rax
movq %rax, 0x28(%rdi)
addq $0x30, %rdi
callq 0x4e90
movq %rax, -0x378(%rbp)
jmp 0x5b44
movq -0x378(%rbp), %rsi
leaq -0x248(%rbp), %rdi
callq 0x4bc0
jmp 0x5b59
movq -0x280(%rbp), %rdi
movq -0x248(%rbp), %rax
movq %rax, 0x30(%rdi)
addq $0x38, %rdi
callq 0x4e90
movq %rax, -0x380(%rbp)
jmp 0x5b7d
movq -0x380(%rbp), %rsi
leaq -0x250(%rbp), %rdi
callq 0x4bc0
jmp 0x5b92
movq -0x280(%rbp), %rdi
movq -0x250(%rbp), %rax
movq %rax, 0x38(%rdi)
addq $0x10, %rdi
callq 0x4e90
movq %rax, -0x388(%rbp)
jmp 0x5bb6
movq -0x388(%rbp), %rsi
leaq -0x258(%rbp), %rdi
callq 0x4bc0
jmp 0x5bcb
movq -0x280(%rbp), %rdi
movq -0x258(%rbp), %rax
movq %rax, 0x10(%rdi)
callq 0x4e90
movq %rax, -0x390(%rbp)
jmp 0x5beb
movq -0x390(%rbp), %rsi
leaq -0x260(%rbp), %rdi
callq 0x4bc0
jmp 0x5c00
movq -0x280(%rbp), %rdi
movq -0x260(%rbp), %rax
movq %rax, (%rdi)
addq $0x8, %rdi
callq 0x4e90
movq %rax, -0x398(%rbp)
jmp 0x5c23
movq -0x398(%rbp), %rsi
leaq -0x268(%rbp), %rdi
callq 0x4bc0
jmp 0x5c38
movq -0x280(%rbp), %rax
movq -0x268(%rbp), %rcx
movq %rcx, 0x8(%rax)
leaq -0x1e0(%rbp), %rdi
callq 0x34a8
leaq -0x1c0(%rbp), %rdi
callq 0x3100
addq $0x3a0, %rsp            # imm = 0x3A0
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x3410
nopw %cs:(%rax,%rax)