// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rdi, (%rsp)
leaq 0x38(%rsp), %rdi
movl $0x8, %edx
callq 0x2200
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x3c5c(%rip), %rdx      # 0x840a
leaq 0x8(%rsp), %rdi
movq %rdx, %rsi
callq 0x4592
movl $0xc, %ebp
movl $0x7, %ebx
movl $0x7, %r14d
subl $0x1, %r14d
jae 0x47e2
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2190
jmp 0x47f6
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl $0x2f, %edx
callq 0x2250
movl %r14d, 0x2c(%rsp)
movq 0x10(%rsp), %r15
testq %r15, %r15
movq %rbx, 0x30(%rsp)
je 0x48da
movq 0x8(%rsp), %r13
leal (,%rbx,8), %r12d
xorl %ebx, %ebx
xorl %r14d, %r14d
movzbl (%r13,%rbx), %eax
leal -0x30(%rax), %ecx
cmpl $0x22, %ecx
ja 0x4866
leaq 0x3acb(%rip), %rdx      # 0x8300
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
addl %eax, %r14d
addl $-0x31, %r14d
movl $0xc, %ebp
leal (%r14,%r12), %esi
incl %r14d
movq (%rsp), %rdi
movl %ebp, %edx
callq 0x4cb4
incq %rbx
cmpq %rbx, %r15
jne 0x4820
jmp 0x48da
leal -0x6b(%rax), %ecx
cmpl $0x7, %ecx
ja 0x4885
leaq 0x3b17(%rip), %rdx      # 0x838c
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movl $0xb, %ebp
jmp 0x484a
cmpl $0x62, %eax
jne 0x484a
movl $0x8, %ebp
jmp 0x484a
movl $0x5, %ebp
jmp 0x484a
movl $0x3, %ebp
jmp 0x484a
movl $0x4, %ebp
jmp 0x484a
xorl %ebp, %ebp
jmp 0x484a
movl $0x2, %ebp
jmp 0x484a
movl $0x1, %ebp
jmp 0x484a
movl $0x9, %ebp
jmp 0x484a
movl $0x7, %ebp
jmp 0x484a
movl $0xa, %ebp
jmp 0x484a
movl $0x6, %ebp
jmp 0x484a
cmpl $0x0, 0x30(%rsp)
movl 0x2c(%rsp), %r14d
movl %r14d, %ebx
jne 0x47cb
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2190
leaq 0x3af2(%rip), %rsi      # 0x83f5
leaq 0x8(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x492b
leaq 0x3adf(%rip), %rsi      # 0x83f7
leaq 0x8(%rsp), %rdi
callq 0x2070
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
jmp 0x492d
xorl %ecx, %ecx
movq (%rsp), %rax
movl %ecx, 0x17c(%rax)
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2190
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x49b8
movq 0x8(%rsp), %rcx
movq (%rsp), %rdx
movq 0x188(%rdx), %rdx
xorl %esi, %esi
movzbl (%rcx,%rsi), %r8d
cmpl $0x50, %r8d
jle 0x4986
cmpl $0x71, %r8d
je 0x499e
cmpl $0x6b, %r8d
je 0x49a5
cmpl $0x51, %r8d
jne 0x49b0
movl $0x2, %edi
jmp 0x49aa
movl $0x0, %edi
cmpl $0x2d, %r8d
je 0x49ad
movl $0x1, %edi
cmpl $0x4b, %r8d
je 0x49aa
jmp 0x49b0
movl $0x8, %edi
jmp 0x49aa
movl $0x4, %edi
orl 0x8(%rdx), %edi
movl %edi, 0x8(%rdx)
incq %rsi
cmpq %rsi, %rax
jne 0x4962
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2190
movq 0x8(%rsp), %rdx
movsbl (%rdx), %eax
movl $0x40, %ecx
cmpl $0x2d, %eax
je 0x49e6
movsbl 0x1(%rdx), %ecx
leal (%rax,%rcx,8), %ecx
addl $0xfffffe17, %ecx       # imm = 0xFFFFFE17
movq (%rsp), %rax
movq 0x188(%rax), %rax
movl %ecx, 0x4(%rax)
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2190
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x4a3a
movq 0x8(%rsp), %rcx
xorl %edx, %edx
xorl %esi, %esi
testl %esi, %esi
je 0x4a29
leal (%rsi,%rsi,4), %esi
movsbl (%rcx,%rdx), %edi
leal (%rdi,%rsi,2), %esi
addl $-0x30, %esi
jmp 0x4a30
movsbl (%rcx,%rdx), %esi
addl $-0x30, %esi
incq %rdx
cmpq %rdx, %rax
jne 0x4a16
jmp 0x4a3c
xorl %esi, %esi
movq (%rsp), %rax
movq 0x188(%rax), %rax
movl %esi, (%rax)
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2190
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x4a8f
xorl %ecx, %ecx
xorl %edx, %edx
testl %edx, %edx
je 0x4a7e
leal (%rdx,%rdx,4), %edx
movsbl (%rdi,%rcx), %esi
leal (%rsi,%rdx,2), %edx
addl $-0x30, %edx
jmp 0x4a85
movsbl (%rdi,%rcx), %edx
addl $-0x30, %edx
incq %rcx
cmpq %rcx, %rax
jne 0x4a6b
jmp 0x4a91
xorl %edx, %edx
movq (%rsp), %rax
movl %edx, 0x178(%rax)
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x4ab2
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x64ff(%rip), %rsi      # 0xafb8
leaq 0x38(%rsp), %rdi
callq 0x21c0
leaq 0xb0(%rsp), %rdi
callq 0x2090
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4aeb
movq %rax, %rbx
jmp 0x4b0a
jmp 0x4aeb
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x4b0a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x64a7(%rip), %rsi      # 0xafb8
leaq 0x38(%rsp), %rdi
callq 0x21c0
leaq 0xb0(%rsp), %rdi
callq 0x2090
movq %rbx, %rdi
callq 0x2230