// File: bjohnsonfl[P]Overhead-Chess-Engine-/position.cpp
// Function: position::fenParser(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
void position::fenParser(std::string &fen){
    
    std::istringstream stream (fen);
    std::string str = "";
    
    rank rk = noRank;
    file f = noFile;
    square sq = empty;
    piece pt = not_piece;
    for(int i =7; i>=0; i--){
        if(i != 0) std::getline(stream, str, '/');
        else stream >> str;
        rk = rank(i);
         f = file_a;
        for (auto it = std::begin(str); it!=std::end(str); ++it)
            {

                switch (*it) {
                        
                    //black pieces
                    case 'p':
                        pt = b_pawn;
                        break;
                    case 'n':
                        pt = b_knight;
                        break;
                    case 'b':
                        pt = b_bishop;
                        break;
                    case 'r':
                        pt = b_rook;
                        break;
                    case 'q':
                        pt = b_queen;
                        break;
                    case 'k':
                        pt = b_king;
                        break;
                        
                    //white pieces
                    case 'P':
                        pt = w_pawn;
                        break;
                    case 'N':
                        pt = w_knight;
                        break;
                    case 'B':
                        pt = w_bishop;
                        break;
                    case 'R':
                        pt = w_rook;
                        break;
                    case 'Q':
                        pt = w_queen;
                        break;
                    case 'K':
                        pt = w_king;
                        break;
                        
                    //file numbers
                    case '0':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    case '8':
                       // std::cout << *it <<std:: endl;
                        f = file(f + file(*it - '1'));
                        pt = not_piece;
                    default:
                        break;
                }
               // std::cout << *it <<std:: endl;
                sq = rankFile_to_sq(rk, f);
                f++;
                place_piece(sq, pt);
            }
        }
    //SIDE TO PLAY
    stream >> str;
    sideToPlay = (str  == "w" || str == "W") ? white : black;
    
    
    //CASTLING RIGHTS
    stream >> str;
    for (auto it = std::begin(str); it!=std::end(str); ++it)
    {
        switch (*it) {
            case '-':
                state -> castling = noRights;
                break;
            case 'K':
                state -> castling |= W_OO;
                break;
            case 'Q':
                 state -> castling |= W_OOO;
                break;
            case 'k':
                 state -> castling |= B_OO;
                break;
            case 'q':
                 state -> castling |= B_OOO;
                break;
                
            default:
                break;
        }
    }
    //ENPASSENT
    stream >> str;
    if( str[0] == '-' ) state -> enPassent = empty;
    else {
        f = file(str[0] - 'a');
        rk = rank ( str[1] - '1');
        sq = rankFile_to_sq(rk, f);
        state -> enPassent = sq;
    }
    
    //Half Move (50 move rule)
    stream >> str;
    int count = 0;
    for (auto it = std::begin(str); it!=std::end(str); ++it)
    {
        if(count == 0) count = *it - '0';
        else {
            count = count * 10;
            count += *it - '0';
        }
    }
    state -> fiftyMove = count;
    
    //Full Move Counter
    stream >> str;
    count = 0;
    for (auto it = std::begin(str); it!=std::end(str); ++it)
    {
        if(count == 0) count = *it - '0';
        else {
            count = count * 10;
            count += *it - '0';
        }
    }
    ply = count;
   
    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2b0, %rsp            # imm = 0x2B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x230(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x190(%rbp), %rdi
movl $0x8, %edx
callq 0x3360
leaq -0x1b1(%rbp), %rdi
movq %rdi, -0x228(%rbp)
callq 0x33a0
movq -0x228(%rbp), %rdx
leaq 0x6842(%rip), %rsi      # 0xe3c6
leaq -0x1b0(%rbp), %rdi
callq 0x3b70
jmp 0x7b92
leaq -0x1b1(%rbp), %rdi
callq 0x3230
movl $0x9, -0x1c8(%rbp)
movl $0x9, -0x1cc(%rbp)
movl $0x40, -0x1d0(%rbp)
movl $0xc, -0x1d4(%rbp)
movl $0x7, -0x1d8(%rbp)
cmpl $0x0, -0x1d8(%rbp)
jl 0x7e67
cmpl $0x0, -0x1d8(%rbp)
je 0x7c48
leaq -0x190(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
movl $0x2f, %edx
callq 0x33c0
jmp 0x7c00
jmp 0x7c5f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1c0(%rbp)
movl %eax, -0x1c4(%rbp)
leaq -0x1b1(%rbp), %rdi
callq 0x3230
jmp 0x833b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1c0(%rbp)
movl %eax, -0x1c4(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x3408
jmp 0x833b
leaq -0x190(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x32a0
jmp 0x7c5d
jmp 0x7c5f
movl -0x1d8(%rbp), %eax
movl %eax, -0x1c8(%rbp)
movl $0x0, -0x1cc(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x9fa0
movq %rax, -0x238(%rbp)
jmp 0x7c8a
movq -0x238(%rbp), %rax
movq %rax, -0x1e0(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0xa010
movq %rax, -0x240(%rbp)
jmp 0x7cad
movq -0x240(%rbp), %rax
movq %rax, -0x1e8(%rbp)
leaq -0x1e0(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x9fd0
testb $0x1, %al
jne 0x7cd7
jmp 0x7e51
leaq -0x1e0(%rbp), %rdi
callq 0xa040
movsbl (%rax), %eax
addl $-0x30, %eax
movl %eax, %ecx
movq %rcx, -0x248(%rbp)
subl $0x42, %eax
ja 0x7ded
movq -0x248(%rbp), %rax
leaq 0x6563(%rip), %rcx      # 0xe26c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x6, -0x1d4(%rbp)
jmp 0x7def
movl $0x7, -0x1d4(%rbp)
jmp 0x7def
movl $0x8, -0x1d4(%rbp)
jmp 0x7def
movl $0x9, -0x1d4(%rbp)
jmp 0x7def
movl $0xa, -0x1d4(%rbp)
jmp 0x7def
movl $0xb, -0x1d4(%rbp)
jmp 0x7def
movl $0x0, -0x1d4(%rbp)
jmp 0x7def
movl $0x1, -0x1d4(%rbp)
jmp 0x7def
movl $0x2, -0x1d4(%rbp)
jmp 0x7def
movl $0x3, -0x1d4(%rbp)
jmp 0x7def
movl $0x4, -0x1d4(%rbp)
jmp 0x7def
movl $0x5, -0x1d4(%rbp)
jmp 0x7def
movl -0x1cc(%rbp), %eax
movl %eax, -0x24c(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0xa040
movq %rax, %rcx
movl -0x24c(%rbp), %eax
movsbl (%rcx), %ecx
subl $0x31, %ecx
addl %ecx, %eax
movl %eax, -0x1cc(%rbp)
movl $0xc, -0x1d4(%rbp)
jmp 0x7def
movl -0x1c8(%rbp), %edi
movl -0x1cc(%rbp), %esi
callq 0x5a00
movl %eax, -0x250(%rbp)
jmp 0x7e08
movl -0x250(%rbp), %eax
movl %eax, -0x1d0(%rbp)
leaq -0x1cc(%rbp), %rdi
xorl %esi, %esi
callq 0x5a20
jmp 0x7e24
movq -0x230(%rbp), %rdi
movl -0x1d0(%rbp), %esi
movl -0x1d4(%rbp), %edx
callq 0x8600
jmp 0x7e3e
jmp 0x7e40
leaq -0x1e0(%rbp), %rdi
callq 0xa060
jmp 0x7c98
jmp 0x7e53
movl -0x1d8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1d8(%rbp)
jmp 0x7bd0
leaq -0x190(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x32a0
jmp 0x7e7c
leaq 0x652e(%rip), %rsi      # 0xe3b1
leaq -0x1b0(%rbp), %rdi
callq 0xa080
movb %al, -0x251(%rbp)
jmp 0x7e97
movb -0x251(%rbp), %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x252(%rbp)
jne 0x7ed5
jmp 0x7eac
leaq 0x6500(%rip), %rsi      # 0xe3b3
leaq -0x1b0(%rbp), %rdi
callq 0xa080
movb %al, -0x253(%rbp)
jmp 0x7ec7
movb -0x253(%rbp), %al
movb %al, -0x252(%rbp)
jmp 0x7ed5
movq -0x230(%rbp), %rax
movb -0x252(%rbp), %cl
notb %cl
movzbl %cl, %ecx
andl $0x1, %ecx
movl %ecx, 0x17c(%rax)
leaq -0x190(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x32a0
jmp 0x7f05
leaq -0x1b0(%rbp), %rdi
callq 0x9fa0
movq %rax, -0x260(%rbp)
jmp 0x7f1a
movq -0x260(%rbp), %rax
movq %rax, -0x1f0(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0xa010
movq %rax, -0x268(%rbp)
jmp 0x7f3d
movq -0x268(%rbp), %rax
movq %rax, -0x1f8(%rbp)
leaq -0x1f0(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0x9fd0
testb $0x1, %al
jne 0x7f67
jmp 0x8047
leaq -0x1f0(%rbp), %rdi
callq 0xa040
movsbl (%rax), %eax
movl %eax, -0x26c(%rbp)
subl $0x2d, %eax
je 0x7fb7
jmp 0x7f83
movl -0x26c(%rbp), %eax
subl $0x4b, %eax
je 0x7fce
jmp 0x7f90
movl -0x26c(%rbp), %eax
subl $0x51, %eax
je 0x7fe7
jmp 0x7f9d
movl -0x26c(%rbp), %eax
subl $0x6b, %eax
je 0x8000
jmp 0x7faa
movl -0x26c(%rbp), %eax
subl $0x71, %eax
je 0x8019
jmp 0x8032
movq -0x230(%rbp), %rax
movq 0x188(%rax), %rax
movl $0x0, 0x8(%rax)
jmp 0x8034
movq -0x230(%rbp), %rax
movq 0x188(%rax), %rax
movl 0x8(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x8(%rax)
jmp 0x8034
movq -0x230(%rbp), %rax
movq 0x188(%rax), %rax
movl 0x8(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x8(%rax)
jmp 0x8034
movq -0x230(%rbp), %rax
movq 0x188(%rax), %rax
movl 0x8(%rax), %ecx
orl $0x4, %ecx
movl %ecx, 0x8(%rax)
jmp 0x8034
movq -0x230(%rbp), %rax
movq 0x188(%rax), %rax
movl 0x8(%rax), %ecx
orl $0x8, %ecx
movl %ecx, 0x8(%rax)
jmp 0x8034
jmp 0x8034
jmp 0x8036
leaq -0x1f0(%rbp), %rdi
callq 0xa060
jmp 0x7f28
leaq -0x190(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x32a0
jmp 0x805c
xorl %eax, %eax
movl %eax, %esi
leaq -0x1b0(%rbp), %rdi
callq 0x33f0
movq %rax, -0x278(%rbp)
jmp 0x8075
movq -0x278(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x809e
movq -0x230(%rbp), %rax
movq 0x188(%rax), %rax
movl $0x40, 0x4(%rax)
jmp 0x8133
xorl %eax, %eax
movl %eax, %esi
leaq -0x1b0(%rbp), %rdi
callq 0x33f0
movq %rax, -0x280(%rbp)
jmp 0x80b7
movq -0x280(%rbp), %rax
movsbl (%rax), %eax
addl $-0x61, %eax
movl %eax, -0x1cc(%rbp)
leaq -0x1b0(%rbp), %rdi
movl $0x1, %esi
callq 0x33f0
movq %rax, -0x288(%rbp)
jmp 0x80e4
movq -0x288(%rbp), %rax
movsbl (%rax), %eax
addl $-0x31, %eax
movl %eax, -0x1c8(%rbp)
movl -0x1c8(%rbp), %edi
movl -0x1cc(%rbp), %esi
callq 0x5a00
movl %eax, -0x28c(%rbp)
jmp 0x8110
movq -0x230(%rbp), %rax
movl -0x28c(%rbp), %ecx
movl %ecx, -0x1d0(%rbp)
movl -0x1d0(%rbp), %ecx
movq 0x188(%rax), %rax
movl %ecx, 0x4(%rax)
leaq -0x190(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x32a0
jmp 0x8148
movl $0x0, -0x1fc(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x9fa0
movq %rax, -0x298(%rbp)
jmp 0x8167
movq -0x298(%rbp), %rax
movq %rax, -0x208(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0xa010
movq %rax, -0x2a0(%rbp)
jmp 0x818a
movq -0x2a0(%rbp), %rax
movq %rax, -0x210(%rbp)
leaq -0x208(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x9fd0
testb $0x1, %al
jne 0x81b1
jmp 0x8212
cmpl $0x0, -0x1fc(%rbp)
jne 0x81d4
leaq -0x208(%rbp), %rdi
callq 0xa040
movsbl (%rax), %eax
subl $0x30, %eax
movl %eax, -0x1fc(%rbp)
jmp 0x81ff
imull $0xa, -0x1fc(%rbp), %eax
movl %eax, -0x1fc(%rbp)
leaq -0x208(%rbp), %rdi
callq 0xa040
movsbl (%rax), %eax
subl $0x30, %eax
addl -0x1fc(%rbp), %eax
movl %eax, -0x1fc(%rbp)
jmp 0x8201
leaq -0x208(%rbp), %rdi
callq 0xa060
jmp 0x8175
movq -0x230(%rbp), %rax
movl -0x1fc(%rbp), %ecx
movq 0x188(%rax), %rax
movl %ecx, (%rax)
leaq -0x190(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x32a0
jmp 0x823d
movl $0x0, -0x1fc(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x9fa0
movq %rax, -0x2a8(%rbp)
jmp 0x825c
movq -0x2a8(%rbp), %rax
movq %rax, -0x218(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0xa010
movq %rax, -0x2b0(%rbp)
jmp 0x827f
movq -0x2b0(%rbp), %rax
movq %rax, -0x220(%rbp)
leaq -0x218(%rbp), %rdi
leaq -0x220(%rbp), %rsi
callq 0x9fd0
testb $0x1, %al
jne 0x82a6
jmp 0x8307
cmpl $0x0, -0x1fc(%rbp)
jne 0x82c9
leaq -0x218(%rbp), %rdi
callq 0xa040
movsbl (%rax), %eax
subl $0x30, %eax
movl %eax, -0x1fc(%rbp)
jmp 0x82f4
imull $0xa, -0x1fc(%rbp), %eax
movl %eax, -0x1fc(%rbp)
leaq -0x218(%rbp), %rdi
callq 0xa040
movsbl (%rax), %eax
subl $0x30, %eax
addl -0x1fc(%rbp), %eax
movl %eax, -0x1fc(%rbp)
jmp 0x82f6
leaq -0x218(%rbp), %rdi
callq 0xa060
jmp 0x826a
movq -0x230(%rbp), %rax
movl -0x1fc(%rbp), %ecx
movl %ecx, 0x178(%rax)
leaq -0x1b0(%rbp), %rdi
callq 0x3408
leaq -0x190(%rbp), %rdi
callq 0x3100
addq $0x2b0, %rsp            # imm = 0x2B0
popq %rbp
retq
leaq -0x190(%rbp), %rdi
callq 0x3100
movq -0x1c0(%rbp), %rdi
callq 0x3390
nopw %cs:(%rax,%rax)