// File: /workspace/github_cpp_makefile_star2_O2/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, 0x8(%rsp)
leaq 0x38(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x2200
leaq 0x2fec(%rip), %rsi      # 0x739e
leaq 0x10(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x26c4
pushq $0x7
popq %rax
pushq $0xc
popq %r13
movl %eax, %r12d
testl %eax, %eax
js 0x44b6
movl %r12d, %eax
subl $0x1, %eax
movl %eax, 0x34(%rsp)
jae 0x43f0
leaq 0x38(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x21a0
jmp 0x4402
leaq 0x38(%rsp), %rdi
leaq 0x10(%rsp), %rsi
pushq $0x2f
popq %rdx
callq 0x2250
movq 0x10(%rsp), %rbp
movq 0x18(%rsp), %r14
shll $0x3, %r12d
xorl %ebx, %ebx
xorl %r15d, %r15d
cmpq %rbx, %r14
je 0x44ad
movzbl (%rbp,%rbx), %eax
leal -0x30(%rax), %ecx
cmpl $0x22, %ecx
ja 0x445f
leaq 0x2e4e(%rip), %rdx      # 0x7280
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
addl %eax, %r15d
addl $-0x31, %r15d
pushq $0xc
popq %r13
leal (%r15,%r12), %esi
incl %r15d
movq 0x8(%rsp), %rdi
movl %r13d, %edx
callq 0x47de
incq %rbx
jmp 0x4415
leal -0x6b(%rax), %ecx
cmpl $0x7, %ecx
ja 0x447b
leaq 0x2e9e(%rip), %rdx      # 0x730c
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
pushq $0xb
jmp 0x4444
cmpl $0x62, %eax
jne 0x4446
pushq $0x8
jmp 0x4444
pushq $0x5
jmp 0x4444
pushq $0x3
jmp 0x4444
pushq $0x4
jmp 0x4444
xorl %r13d, %r13d
jmp 0x4446
pushq $0x2
jmp 0x4444
pushq $0x1
jmp 0x4444
pushq $0x9
jmp 0x4444
pushq $0x7
jmp 0x4444
pushq $0xa
jmp 0x4444
pushq $0x6
jmp 0x4444
movl 0x34(%rsp), %eax
jmp 0x43c8
leaq 0x38(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x21a0
leaq 0x2ebd(%rip), %rsi      # 0x7389
leaq 0x10(%rsp), %rdi
callq 0x5634
xorl %ecx, %ecx
testb %al, %al
jne 0x44f2
leaq 0x2ea8(%rip), %rsi      # 0x738b
leaq 0x10(%rsp), %rdi
callq 0x5634
xorb $0x1, %al
movzbl %al, %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x17c(%rax)
leaq 0x38(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x21a0
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %rdx
movq 0x188(%rdx), %rdx
xorl %esi, %esi
pushq $0x1
popq %rdi
pushq $0x8
popq %r8
pushq $0x4
popq %r9
pushq $0x2
popq %r10
cmpq %rsi, %rcx
je 0x4577
movzbl (%rax,%rsi), %ebx
cmpl $0x2d, %ebx
je 0x4572
movl %edi, %r11d
cmpl $0x4b, %ebx
je 0x4565
cmpl $0x71, %ebx
je 0x4562
cmpl $0x6b, %ebx
je 0x455d
cmpl $0x51, %ebx
jne 0x456d
movl %r10d, %r11d
jmp 0x4565
movl %r9d, %r11d
jmp 0x4565
movl %r8d, %r11d
orl 0x8(%rdx), %r11d
movl %r11d, 0x8(%rdx)
incq %rsi
jmp 0x4533
xorl %r11d, %r11d
jmp 0x4569
leaq 0x38(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x21a0
movq 0x10(%rsp), %rcx
movsbl (%rcx), %eax
cmpl $0x2d, %eax
jne 0x4598
pushq $0x40
popq %rax
jmp 0x45a4
movsbl 0x1(%rcx), %ecx
leal (%rax,%rcx,8), %eax
addl $0xfffffe17, %eax       # imm = 0xFFFFFE17
movq 0x8(%rsp), %rcx
movq 0x188(%rcx), %rcx
movl %eax, 0x4(%rcx)
leaq 0x38(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x21a0
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
xorl %edx, %edx
xorl %esi, %esi
cmpq %rdx, %rcx
je 0x45f3
testl %esi, %esi
je 0x45e7
imull $0xa, %esi, %esi
movsbl (%rax,%rdx), %edi
addl %edi, %esi
addl $-0x30, %esi
jmp 0x45ee
movsbl (%rax,%rdx), %esi
addl $-0x30, %esi
incq %rdx
jmp 0x45d0
movq 0x8(%rsp), %rax
movq 0x188(%rax), %rax
movl %esi, (%rax)
leaq 0x38(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x21a0
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
xorl %edx, %edx
xorl %esi, %esi
cmpq %rdx, %rcx
je 0x4641
testl %esi, %esi
je 0x4635
imull $0xa, %esi, %esi
movsbl (%rax,%rdx), %edi
addl %edi, %esi
addl $-0x30, %esi
jmp 0x463c
movsbl (%rax,%rdx), %esi
addl $-0x30, %esi
incq %rdx
jmp 0x461e
movq 0x8(%rsp), %rax
movl %esi, 0x178(%rax)
leaq 0x10(%rsp), %rdi
callq 0x2288
leaq 0x38(%rsp), %rdi
callq 0x20c0
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x467b
movq %rax, %rbx
jmp 0x4688
jmp 0x467b
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2288
leaq 0x38(%rsp), %rdi
callq 0x20c0
movq %rbx, %rdi
callq 0x2230