// File: /workspace/github_cpp_makefile_star2_O3/bjohnsonfl[P]Overhead-Chess-Engine-/UCI.cpp
// Function: UCI::parsePosition(std::__cxx11::basic_istringstream<char, std::char_traits<char>, std::allocator<char>>&, returnState&)
void UCI::parsePosition(std::istringstream &stream, returnState& newState)
{
    logFile.open("log.txt" , std::ofstream::app);
    move m = none;
    std::string token, fen;
    
    stream >> token;
   
    
    if( token == "startpos")
    {
    
        pos.reset();
        stream >> token;
    }
    else if ( token == "fen")
    {
       //credit to stockfish
        while (stream >> token && token != "moves")
            fen += token + " ";
        std::cout<<fen;
         logFile << fen << "\n";
        pos.updatePositionFen(fen);
        pos.printBoard();
    }
  
    else return;
    

    while (stream >> token && ((m = moveCheck(token)) != none))
    {
       // returnState newState = returnState();
       // newState = returnState();
        logFile << token << " ";
        //Ok this is a memory leak. fix this with an array of 256 structs 
        returnState * nnewState = new returnState();
        pos.do_move(m, *nnewState);
        pos.printBoard();
    }
        pos.printBoard();
    
    logFile << "Ply: " << pos.get_ply() << "\n";
    logFile.close();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %r15
movq %rdi, 0x10(%rsp)
addq $0x1b0, %rdi            # imm = 0x1B0
leaq 0x1ca3(%rip), %rsi      # 0x8590
movq %rdi, 0x8(%rsp)
movl $0x1, %edx
callq 0x2050
leaq 0x28(%rsp), %rbx
movq %rbx, -0x10(%rbx)
xorl %eax, %eax
movq %rax, -0x8(%rbx)
movb %al, (%rbx)
leaq 0x48(%rsp), %r14
movq %r14, -0x10(%r14)
movq %rax, -0x8(%r14)
movb %al, (%r14)
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x2190
leaq 0x1c67(%rip), %rsi      # 0x8598
leaq 0x18(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x69f7
leaq 0x1c57(%rip), %rsi      # 0x85a1
leaq 0x18(%rsp), %rdi
callq 0x2070
testl %eax, %eax
jne 0x6c02
leaq 0x68(%rsp), %r14
leaq 0x18(%rsp), %rbx
leaq 0x1c38(%rip), %r12      # 0x85a5
leaq 0x58(%rsp), %r13
leaq 0x38(%rsp), %rbp
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2190
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x6a17
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2070
testl %eax, %eax
je 0x6a17
movq %r14, 0x58(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x7900
movq %r13, %rdi
leaq 0x1ca8(%rip), %rsi      # 0x866f
callq 0x2260
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq %rbp, %rdi
callq 0x2080
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0x6977
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x6977
movq 0x10(%rsp), %rax
leaq 0x18(%rax), %rdi
callq 0x463a
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x2190
jmp 0x6ab9
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x4598(%rip), %rdi      # 0xafc0
callq 0x2180
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x8(%rsp), %rdi
callq 0x2180
leaq 0x19c1(%rip), %rsi      # 0x8409
movl $0x1, %edx
movq %rax, %rdi
callq 0x2180
leaq 0xa8(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
addq %rsi, %rdx
leaq 0x98(%rsp), %rdi
callq 0x7900
movq 0x10(%rsp), %rax
leaq 0x18(%rax), %rbx
leaq 0x98(%rsp), %rsi
movq %rbx, %rdi
callq 0x46a4
movq 0x98(%rsp), %rdi
cmpq %r14, %rdi
je 0x6ab1
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x2160
movq %rbx, %rdi
callq 0x5298
leaq 0x88(%rsp), %rbx
movq 0x10(%rsp), %rax
leaq 0x18(%rax), %r12
leaq 0x18(%rsp), %r13
leaq 0x78(%rsp), %rbp
movq %r15, %rdi
movq %r13, %rsi
callq 0x2190
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x6ba7
movq %rbx, 0x78(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0x7900
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x76d0
movl %eax, %r14d
movq 0x78(%rsp), %rdi
cmpq %rbx, %rdi
je 0x6b35
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2160
testl %r14d, %r14d
je 0x6ba7
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x8(%rsp), %rdi
callq 0x2180
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1b12(%rip), %rsi      # 0x866f
callq 0x2180
movl $0x48, %edi
callq 0x2150
movaps 0x176d(%rip), %xmm0     # 0x82e0
movups %xmm0, (%rax)
movl $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x28(%rax)
movups %xmm0, 0x38(%rax)
movq %r12, %rdi
movl %r14d, %esi
movq %rax, %rdx
callq 0x4d16
movq %r12, %rdi
callq 0x5298
jmp 0x6ad4
movq %r12, %rdi
leaq 0x28(%rsp), %rbx
leaq 0x48(%rsp), %r14
callq 0x5298
leaq 0x19eb(%rip), %rsi      # 0x85ab
movl $0x5, %edx
movq 0x8(%rsp), %rdi
callq 0x2180
movq 0x10(%rsp), %rax
movl 0x190(%rax), %esi
movq 0x8(%rsp), %rdi
callq 0x2220
leaq 0x181e(%rip), %rsi      # 0x8409
movl $0x1, %edx
movq %rax, %rdi
callq 0x2180
movq 0x8(%rsp), %rdi
callq 0x21b0
movq 0x38(%rsp), %rdi
cmpq %r14, %rdi
je 0x6c19
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x18(%rsp), %rdi
cmpq %rbx, %rdi
je 0x6c30
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2160
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movq 0x98(%rsp), %rdi
cmpq %r14, %rdi
je 0x6c9c
movq 0xa8(%rsp), %rsi
jmp 0x6c8d
jmp 0x6c60
jmp 0x6c99
movq %rax, %r15
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0x6c9c
movq 0x68(%rsp), %rsi
jmp 0x6c8d
jmp 0x6c99
jmp 0x6c99
movq %rax, %r15
movq 0x78(%rsp), %rdi
cmpq %rbx, %rdi
je 0x6c9c
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x6c9c
jmp 0x6c99
movq %rax, %r15
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x6cb8
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x6cd4
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2160
movq %r15, %rdi
callq 0x2230