// File: /workspace/github_cpp_makefile_star2_O1/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, 0x8(%rsp)
addq $0x1b0, %rdi            # imm = 0x1B0
leaq 0x1c2b(%rip), %rsi      # 0x84c4
movq %rdi, 0x10(%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 0x1bef(%rip), %rsi      # 0x84cc
leaq 0x18(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x69a3
leaq 0x1bdf(%rip), %rsi      # 0x84d5
leaq 0x18(%rsp), %rdi
callq 0x2070
testl %eax, %eax
jne 0x6bd4
leaq 0x68(%rsp), %rbx
leaq 0x18(%rsp), %r14
leaq 0x1bc0(%rip), %r12      # 0x84d9
leaq 0x58(%rsp), %r13
leaq 0x38(%rsp), %rbp
movq %r15, %rdi
movq %r14, %rsi
callq 0x2190
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x69c3
movq %r14, %rdi
movq %r12, %rsi
callq 0x2070
testl %eax, %eax
je 0x69c3
movq %rbx, 0x58(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x78ce
movq %r13, %rdi
leaq 0x1c30(%rip), %rsi      # 0x85a3
callq 0x2260
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq %rbp, %rdi
callq 0x2080
movq 0x58(%rsp), %rdi
cmpq %rbx, %rdi
je 0x6923
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x6923
movq 0x8(%rsp), %rax
leaq 0x18(%rax), %rdi
callq 0x4596
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x2190
jmp 0x6a65
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x45ec(%rip), %rdi      # 0xafc0
callq 0x2180
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x10(%rsp), %rdi
callq 0x2180
leaq 0x197d(%rip), %rsi      # 0x8371
movl $0x1, %edx
movq %rax, %rdi
callq 0x2180
leaq 0xa8(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
addq %rsi, %rdx
leaq 0x98(%rsp), %rdi
callq 0x78ce
movq 0x8(%rsp), %rax
leaq 0x18(%rax), %r14
leaq 0x98(%rsp), %rsi
movq %r14, %rdi
callq 0x4612
movq 0x98(%rsp), %rdi
cmpq %rbx, %rdi
je 0x6a5d
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x2160
movq %r14, %rdi
callq 0x5244
movq 0x8(%rsp), %rax
leaq 0x18(%rax), %r12
xorl %ebp, %ebp
leaq 0x18(%rsp), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x2190
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x20(%rax,%rcx), %ebx
testb $0x5, %bl
je 0x6a95
xorl %r14d, %r14d
jmp 0x6ad0
leaq 0x88(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
leaq 0x78(%rsp), %rdi
callq 0x78ce
movq 0x8(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x76a4
movl %eax, %ebp
testl %eax, %eax
setne %r14b
testb $0x5, %bl
jne 0x6af7
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x6af7
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2160
testb %r14b, %r14b
je 0x6b79
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rdi
callq 0x2180
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1a84(%rip), %rsi      # 0x85a3
callq 0x2180
movl $0x48, %edi
callq 0x2150
movabsq $0xc00000000, %rcx      # imm = 0xC00000000
movq %rcx, 0x8(%rax)
movabsq $0x4000000000, %rcx     # imm = 0x4000000000
movq %rcx, (%rax)
movl $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x28(%rax)
movups %xmm0, 0x38(%rax)
movq %r12, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0x4c60
movq %r12, %rdi
callq 0x5244
jmp 0x6a75
movq %r12, %rdi
leaq 0x28(%rsp), %rbx
leaq 0x48(%rsp), %r14
callq 0x5244
leaq 0x194d(%rip), %rsi      # 0x84df
movl $0x5, %edx
movq 0x10(%rsp), %rdi
callq 0x2180
movq 0x8(%rsp), %rax
movl 0x190(%rax), %esi
movq 0x10(%rsp), %rdi
callq 0x2220
leaq 0x17b4(%rip), %rsi      # 0x8371
movl $0x1, %edx
movq %rax, %rdi
callq 0x2180
movq 0x10(%rsp), %rdi
callq 0x21b0
movq 0x38(%rsp), %rdi
cmpq %r14, %rdi
je 0x6beb
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x18(%rsp), %rdi
cmpq %rbx, %rdi
je 0x6c02
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, %r14
movq 0x98(%rsp), %rdi
cmpq %rbx, %rdi
je 0x6c76
movq 0xa8(%rsp), %rsi
jmp 0x6c67
jmp 0x6c32
jmp 0x6c73
movq %rax, %r14
movq 0x58(%rsp), %rdi
cmpq %rbx, %rdi
je 0x6c76
movq 0x68(%rsp), %rsi
jmp 0x6c67
jmp 0x6c73
jmp 0x6c73
movq %rax, %r14
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x6c76
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x6c76
jmp 0x6c73
movq %rax, %r14
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
leaq 0x28(%rsp), %rbx
je 0x6c97
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x18(%rsp), %rdi
cmpq %rbx, %rdi
je 0x6cae
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2160
movq %r14, %rdi
callq 0x2230