// File: 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
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
addq $0x1b0, %rdi            # imm = 0x1B0
leaq 0x2d48(%rip), %rsi      # 0xe518
movl $0x1, %edx
callq 0x3040
movl $0x0, -0x1c(%rbp)
leaq -0x40(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x32e0
leaq -0x60(%rbp), %rdi
callq 0x32e0
movq -0xf0(%rbp), %rsi
movq -0x10(%rbp), %rdi
callq 0x32a0
jmp 0xb80c
leaq 0x2d0d(%rip), %rsi      # 0xe520
leaq -0x40(%rbp), %rdi
callq 0xa080
movb %al, -0xf9(%rbp)
jmp 0xb824
movb -0xf9(%rbp), %al
testb $0x1, %al
jne 0xb830
jmp 0xb867
movq -0xf8(%rbp), %rdi
addq $0x18, %rdi
callq 0x7900
jmp 0xb842
movq -0x10(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x32a0
jmp 0xb851
jmp 0xba32
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xbc97
leaq 0x2cbb(%rip), %rsi      # 0xe529
leaq -0x40(%rbp), %rdi
callq 0xa080
movb %al, -0xfa(%rbp)
jmp 0xb87f
movb -0xfa(%rbp), %al
testb $0x1, %al
jne 0xb88e
jmp 0xba21
jmp 0xb890
movq -0x10(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x32a0
movq %rax, -0x108(%rbp)
jmp 0xb8a6
movq -0x108(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3290
movb %al, -0x109(%rbp)
jmp 0xb8c4
movb -0x109(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x10a(%rbp)
jne 0xb8d9
jmp 0xb8ff
leaq 0x2c4d(%rip), %rsi      # 0xe52d
leaq -0x40(%rbp), %rdi
callq 0xcd60
movb %al, -0x10b(%rbp)
jmp 0xb8f1
movb -0x10b(%rbp), %al
movb %al, -0x10a(%rbp)
jmp 0xb8ff
movb -0x10a(%rbp), %al
testb $0x1, %al
jne 0xb90b
jmp 0xb964
leaq 0x2ce5(%rip), %rdx      # 0xe5f7
leaq -0x90(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xcd90
jmp 0xb924
leaq -0x60(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x32b0
jmp 0xb936
leaq -0x90(%rbp), %rdi
callq 0x3408
jmp 0xb890
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x3408
jmp 0xbc97
movq 0x665d(%rip), %rdi      # 0x11fc8
leaq -0x60(%rbp), %rsi
callq 0x31d0
jmp 0xb976
movq -0xf8(%rbp), %rdi
addq $0x1b0, %rdi            # imm = 0x1B0
leaq -0x60(%rbp), %rsi
callq 0x31d0
movq %rax, -0x118(%rbp)
jmp 0xb996
movq -0x118(%rbp), %rdi
leaq 0x2a21(%rip), %rsi      # 0xe3c5
callq 0x31e0
jmp 0xb9ab
movq -0xf8(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x120(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x30d0
jmp 0xb9cf
movq -0x120(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x79e0
jmp 0xb9e4
leaq -0xb0(%rbp), %rdi
callq 0x3408
movq -0xf8(%rbp), %rdi
addq $0x18, %rdi
callq 0x9120
jmp 0xba02
jmp 0xba30
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x3408
jmp 0xbc97
movl $0x1, -0xb4(%rbp)
jmp 0xbc7c
jmp 0xba32
jmp 0xba34
movq -0x10(%rbp), %rdi
movb $0x0, -0xd9(%rbp)
leaq -0x40(%rbp), %rsi
callq 0x32a0
movq %rax, -0x128(%rbp)
jmp 0xba51
movq -0x128(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3290
movb %al, -0x129(%rbp)
jmp 0xba6f
movb -0x129(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x12a(%rbp)
jne 0xba84
jmp 0xbacd
leaq -0xd8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x30d0
jmp 0xba96
movq -0xf8(%rbp), %rdi
movb $0x1, -0xd9(%rbp)
leaq -0xd8(%rbp), %rsi
callq 0xc800
movl %eax, -0x130(%rbp)
jmp 0xbab8
movl -0x130(%rbp), %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, %eax
setne %al
movb %al, -0x12a(%rbp)
movb -0x12a(%rbp), %al
movb %al, -0x131(%rbp)
testb $0x1, -0xd9(%rbp)
jne 0xbae4
jmp 0xbaf0
leaq -0xd8(%rbp), %rdi
callq 0x3408
movb -0x131(%rbp), %al
testb $0x1, %al
jne 0xbaff
jmp 0xbbe0
movq -0xf8(%rbp), %rdi
addq $0x1b0, %rdi            # imm = 0x1B0
leaq -0x40(%rbp), %rsi
callq 0x31d0
movq %rax, -0x140(%rbp)
jmp 0xbb1f
movq -0x140(%rbp), %rdi
leaq 0x2aca(%rip), %rsi      # 0xe5f7
callq 0x31e0
jmp 0xbb34
movl $0x48, %edi
callq 0x31f0
movq %rax, -0x148(%rbp)
jmp 0xbb47
movq -0x148(%rbp), %rdi
callq 0x9f10
jmp 0xbb55
movq -0xf8(%rbp), %rdi
movq -0x148(%rbp), %rax
movq %rax, -0xe8(%rbp)
addq $0x18, %rdi
movl -0x1c(%rbp), %esi
movq -0xe8(%rbp), %rdx
callq 0x86f0
jmp 0xbb7f
movq -0xf8(%rbp), %rdi
addq $0x18, %rdi
callq 0x9120
jmp 0xbb91
jmp 0xba34
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
testb $0x1, -0xd9(%rbp)
jne 0xbbad
jmp 0xbbb9
leaq -0xd8(%rbp), %rdi
callq 0x3408
jmp 0xbc97
movq -0x148(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
movl $0x48, %esi
callq 0x3200
jmp 0xbc97
movq -0xf8(%rbp), %rdi
addq $0x18, %rdi
callq 0x9120
jmp 0xbbf2
movq -0xf8(%rbp), %rdi
addq $0x1b0, %rdi            # imm = 0x1B0
leaq 0x292c(%rip), %rsi      # 0xe533
callq 0x31e0
movq %rax, -0x150(%rbp)
jmp 0xbc15
movq -0xf8(%rbp), %rdi
addq $0x18, %rdi
callq 0xad90
movl %eax, -0x154(%rbp)
jmp 0xbc2d
movl -0x154(%rbp), %esi
movq -0x150(%rbp), %rdi
callq 0x3380
movq %rax, -0x160(%rbp)
jmp 0xbc48
movq -0x160(%rbp), %rdi
leaq 0x276f(%rip), %rsi      # 0xe3c5
callq 0x31e0
jmp 0xbc5d
movq -0xf8(%rbp), %rdi
addq $0x1b0, %rdi            # imm = 0x1B0
callq 0x32f0
jmp 0xbc72
movl $0x0, -0xb4(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x3408
leaq -0x40(%rbp), %rdi
callq 0x3408
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
leaq -0x60(%rbp), %rdi
callq 0x3408
leaq -0x40(%rbp), %rdi
callq 0x3408
movq -0x68(%rbp), %rdi
callq 0x3390
nopw %cs:(%rax,%rax)