// File: /workspace/github_cpp_makefile_star2_O1/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 0x3c54(%rip), %rdx      # 0x8372
leaq 0x8(%rsp), %rdi
movq %rdx, %rsi
callq 0x44f4
movl $0xc, %ebp
movl $0x7, %ebx
movl $0x7, %r14d
subl $0x1, %r14d
jae 0x4752
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2190
jmp 0x4766
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 0x484d
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 0x47d9
leaq 0x3ac3(%rip), %rdx      # 0x8268
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movsbl %al, %eax
addl %eax, %r14d
addl $-0x31, %r14d
movl $0xc, %ebp
leal (%r14,%r12), %esi
incl %r14d
movq (%rsp), %rdi
movl %ebp, %edx
callq 0x4c16
incq %rbx
cmpq %rbx, %r15
jne 0x4790
jmp 0x484d
leal -0x6b(%rax), %ecx
cmpl $0x7, %ecx
ja 0x47f8
leaq 0x3b0c(%rip), %rdx      # 0x82f4
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movl $0xb, %ebp
jmp 0x47bd
cmpl $0x62, %eax
jne 0x47bd
movl $0x8, %ebp
jmp 0x47bd
movl $0x5, %ebp
jmp 0x47bd
movl $0x3, %ebp
jmp 0x47bd
movl $0x4, %ebp
jmp 0x47bd
xorl %ebp, %ebp
jmp 0x47bd
movl $0x2, %ebp
jmp 0x47bd
movl $0x1, %ebp
jmp 0x47bd
movl $0x9, %ebp
jmp 0x47bd
movl $0x7, %ebp
jmp 0x47bd
movl $0xa, %ebp
jmp 0x47bd
movl $0x6, %ebp
jmp 0x47bd
cmpl $0x0, 0x30(%rsp)
movl 0x2c(%rsp), %r14d
movl %r14d, %ebx
jne 0x473b
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2190
leaq 0x3ae7(%rip), %rsi      # 0x835d
leaq 0x8(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x489e
leaq 0x3ad4(%rip), %rsi      # 0x835f
leaq 0x8(%rsp), %rdi
callq 0x2070
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
jmp 0x48a0
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 0x491e
movq 0x8(%rsp), %rcx
movq (%rsp), %rdx
movq 0x188(%rdx), %rdx
xorl %esi, %esi
movzbl (%rcx,%rsi), %edi
cmpl $0x50, %edi
jle 0x48f3
cmpl $0x51, %edi
je 0x4903
cmpl $0x6b, %edi
je 0x4909
cmpl $0x71, %edi
jne 0x4916
orb $0x8, 0x8(%rdx)
jmp 0x4916
cmpl $0x2d, %edi
je 0x490f
cmpl $0x4b, %edi
jne 0x4916
orb $0x1, 0x8(%rdx)
jmp 0x4916
orb $0x2, 0x8(%rdx)
jmp 0x4916
orb $0x4, 0x8(%rdx)
jmp 0x4916
movl $0x0, 0x8(%rdx)
incq %rsi
cmpq %rsi, %rax
jne 0x48d5
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2190
movq 0x8(%rsp), %rdx
movsbl (%rdx), %eax
movl $0x40, %ecx
cmpl $0x2d, %eax
je 0x494c
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 0x49a0
movq 0x8(%rsp), %rcx
xorl %edx, %edx
xorl %esi, %esi
testl %esi, %esi
je 0x498f
leal (%rsi,%rsi,4), %esi
movsbl (%rcx,%rdx), %edi
leal (%rdi,%rsi,2), %esi
addl $-0x30, %esi
jmp 0x4996
movsbl (%rcx,%rdx), %esi
addl $-0x30, %esi
incq %rdx
cmpq %rdx, %rax
jne 0x497c
jmp 0x49a2
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 0x49f5
xorl %ecx, %ecx
xorl %edx, %edx
testl %edx, %edx
je 0x49e4
leal (%rdx,%rdx,4), %edx
movsbl (%rdi,%rcx), %esi
leal (%rsi,%rdx,2), %edx
addl $-0x30, %edx
jmp 0x49eb
movsbl (%rdi,%rcx), %edx
addl $-0x30, %edx
incq %rcx
cmpq %rcx, %rax
jne 0x49d1
jmp 0x49f7
xorl %edx, %edx
movq (%rsp), %rax
movl %edx, 0x178(%rax)
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x4a18
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x6599(%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 0x4a51
movq %rax, %rbx
jmp 0x4a70
jmp 0x4a51
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x4a70
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x6541(%rip), %rsi      # 0xafb8
leaq 0x38(%rsp), %rdi
callq 0x21c0
leaq 0xb0(%rsp), %rdi
callq 0x2090
movq %rbx, %rdi
callq 0x2230