// File: /workspace/github_cpp_makefile_star2_O2/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 0x12d5(%rip), %rsi      # 0x74f0
pushq $0x1
popq %rdx
movq %rdi, 0x10(%rsp)
callq 0x2040
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x21a0
leaq 0x129a(%rip), %rsi      # 0x74f8
leaq 0x18(%rsp), %rdi
callq 0x5634
testb %al, %al
je 0x628c
movq 0x8(%rsp), %rax
leaq 0x18(%rax), %rdi
callq 0x4270
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x21a0
jmp 0x6376
leaq 0x126e(%rip), %rsi      # 0x7501
leaq 0x18(%rsp), %rdi
callq 0x5634
testb %al, %al
je 0x6470
leaq 0x18(%rsp), %rbx
leaq 0x1254(%rip), %r14      # 0x7505
leaq 0x1317(%rip), %r12      # 0x75cf
leaq 0x98(%rsp), %r13
leaq 0x38(%rsp), %rbp
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x6310
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6c50
testb %al, %al
je 0x6310
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x6c5a
movq %rbp, %rdi
movq %r13, %rsi
callq 0x2270
movq %r13, %rdi
callq 0x2288
jmp 0x62c5
movq 0x4c99(%rip), %rdi      # 0xafb0
leaq 0x38(%rsp), %rsi
callq 0x2160
leaq 0x38(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x2160
leaq 0x1066(%rip), %rsi      # 0x739d
movq %rax, %rdi
callq 0x2170
leaq 0x58(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x21b0
movq 0x8(%rsp), %rax
leaq 0x18(%rax), %rbx
leaq 0x58(%rsp), %rsi
movq %rbx, %rdi
callq 0x42d4
leaq 0x58(%rsp), %rdi
callq 0x2288
movq %rbx, %rdi
callq 0x4db0
movq 0x8(%rsp), %rax
leaq 0x18(%rax), %r12
leaq 0x18(%rsp), %r13
leaq 0x78(%rsp), %rbp
pushq $0x48
popq %r14
movq %r15, %rdi
movq %r13, %rsi
callq 0x21a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x642b
movq %rbp, %rdi
movq %r13, %rsi
callq 0x21b0
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x6ab0
movl %eax, %ebx
movq %rbp, %rdi
callq 0x2288
testl %ebx, %ebx
je 0x642b
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x2160
movq %rax, %rdi
leaq 0x11e8(%rip), %rsi      # 0x75cf
callq 0x2170
movq %r14, %rdi
callq 0x2180
movaps 0xe75(%rip), %xmm0      # 0x7270
movups %xmm0, (%rax)
andl $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x28(%rax)
movups %xmm0, 0x38(%rax)
movq %r12, %rdi
movl %ebx, %esi
movq %rax, %rdx
callq 0x4840
movq %r12, %rdi
callq 0x4db0
jmp 0x638d
movq %r12, %rdi
callq 0x4db0
leaq 0x10d1(%rip), %rsi      # 0x750b
movq 0x10(%rsp), %rdi
callq 0x2170
movq 0x8(%rsp), %rcx
movl 0x190(%rcx), %esi
movq %rax, %rdi
callq 0x2220
leaq 0xf3f(%rip), %rsi       # 0x739d
movq %rax, %rdi
callq 0x2170
movq 0x10(%rsp), %rdi
callq 0x21c0
leaq 0x38(%rsp), %rdi
callq 0x2288
leaq 0x18(%rsp), %rdi
callq 0x2288
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
jmp 0x64bb
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
jmp 0x64bb
jmp 0x64c4
jmp 0x64c4
jmp 0x64c4
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x2288
jmp 0x64c7
jmp 0x64c4
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x2288
leaq 0x18(%rsp), %rdi
callq 0x2288
movq %rbx, %rdi
callq 0x2230
nop