// File: /workspace/github_cpp_makefile_star2_O3/SethKasmann[P]clever-girl/src/uci.cpp
// Function: position(std::__cxx11::basic_istringstream<char, std::char_traits<char>, std::allocator<char>>&, State&)
void position(std::istringstream & is, State & s)
{
    std::string token, fen;
    Move m;
    bool start_flag = false;

    s = State(Start_fen);
    history.init();
    history.push(std::make_pair(nullMove, s.getKey()));

    is >> token;
    if (token == "fen")
    {
        while (is >> token && token != "moves")
            fen += token + " ";
    }
    else if (token == "startpos")
    {
        start_flag = true;
        is >> token;
    }
    else
    {
        std::cout << "unknown command\n";
        return;
    }

    while (is >> token)
    {
        m = get_uci_move(token, s);
        if (m == nullMove)
        {
            std::cout << "illegal move found: " << token << '\n' << s;
            return;
        }
        else
        {
            s.make_t(m);
            history.push(std::make_pair(m, s.getKey()));
        }
    }
    // If start flag is false, initialize board state with fen string.
    if (!start_flag)
        s = State(fen);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x558, %rsp            # imm = 0x558
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x18(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x40(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x14b6a1(%rip), %rsi    # 0x164e20
leaq 0x50(%rsp), %rdi
callq 0x1655c
leaq 0x50(%rsp), %rsi
movq %rbx, %rdi
callq 0x1646c
leaq 0x140f03(%rip), %r15    # 0x15a6a0
movq %r15, %rdi
callq 0x1a018
movq 0x18(%rbx), %rax
movw $0x0, 0x50(%rsp)
movq %rax, 0x58(%rsp)
movq 0x8(%r15), %rsi
cmpq 0x10(%r15), %rsi
je 0x197ce
movups 0x50(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%r15)
jmp 0x197df
leaq 0x140ecb(%rip), %rdi    # 0x15a6a0
leaq 0x50(%rsp), %rdx
callq 0x14a78
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x42b0
leaq 0x6c40(%rip), %rsi      # 0x20433
leaq 0x8(%rsp), %rdi
callq 0x4090
movl %eax, 0x2c(%rsp)
testl %eax, %eax
je 0x1983b
leaq 0x6c2b(%rip), %rsi      # 0x20437
leaq 0x8(%rsp), %rdi
callq 0x4090
testl %eax, %eax
je 0x198cf
movq 0xb77b(%rip), %rdi      # 0x24fa0
leaq 0x6c14(%rip), %rsi      # 0x20440
movl $0x10, %edx
callq 0x4290
jmp 0x199c3
leaq 0x60(%rsp), %r13
leaq 0x8(%rsp), %r12
leaq 0x50(%rsp), %rbp
movq %r14, %rdi
movq %r12, %rsi
callq 0x42b0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x198dc
movq %r12, %rdi
leaq 0x6b61(%rip), %rsi      # 0x203ce
callq 0x4090
testl %eax, %eax
je 0x198dc
movq %r13, 0x50(%rsp)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0xfc5e
movq %rbp, %rdi
leaq 0x2ce1(%rip), %rsi      # 0x1c57b
callq 0x43e0
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
leaq 0x30(%rsp), %rdi
callq 0x40b0
movq 0x50(%rsp), %rdi
cmpq %r13, %rdi
je 0x1984a
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4250
jmp 0x1984a
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x42b0
leaq 0x8(%rsp), %r12
leaq 0x50(%rsp), %r13
movq %r14, %rdi
movq %r12, %rsi
callq 0x42b0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x19950
movq %r12, %rdi
movq %rbx, %rsi
callq 0x19254
movl %eax, %ebp
testw %ax, %ax
je 0x19975
movzwl %bp, %esi
movq %rbx, %rdi
callq 0x17a3a
movq 0x18(%rbx), %rax
movw %bp, 0x50(%rsp)
movq %rax, 0x58(%rsp)
movq 0x8(%r15), %rsi
cmpq 0x10(%r15), %rsi
je 0x19943
movups 0x50(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%r15)
jmp 0x198e6
movq %r15, %rdi
movq %r13, %rdx
callq 0x14a78
jmp 0x198e6
cmpl $0x0, 0x2c(%rsp)
jne 0x199c3
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x1655c
leaq 0x50(%rsp), %rsi
movq %rbx, %rdi
callq 0x1646c
jmp 0x199c3
movq 0xb624(%rip), %rdi      # 0x24fa0
leaq 0x6a51(%rip), %rsi      # 0x203d4
movl $0x14, %edx
callq 0x4290
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0xb602(%rip), %rdi      # 0x24fa0
callq 0x4290
leaq 0x50(%rsp), %rsi
movb $0xa, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0x4290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x18775
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x199df
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4250
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x199fb
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4250
addq $0x558, %rsp            # imm = 0x558
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x19a39
jmp 0x19a39
jmp 0x19a39
jmp 0x19a39
jmp 0x19a39
jmp 0x19a1b
jmp 0x19a39
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %r13, %rdi
je 0x19a3c
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4250
jmp 0x19a3c
jmp 0x19a39
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x19a58
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4250
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x19a74
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4250
movq %rbx, %rdi
callq 0x43b0