// File: /workspace/github_cpp_makefile_star2_O1/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 0x14b587(%rip), %rsi    # 0x164e20
leaq 0x50(%rsp), %rdi
callq 0x16640
leaq 0x50(%rsp), %rsi
movq %rbx, %rdi
callq 0x16550
leaq 0x140de9(%rip), %r15    # 0x15a6a0
movq %r15, %rdi
callq 0x1a158
movq 0x18(%rbx), %rax
movw $0x0, 0x50(%rsp)
movq %rax, 0x58(%rsp)
movq 0x8(%r15), %rsi
cmpq 0x10(%r15), %rsi
je 0x198e8
movups 0x50(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%r15)
jmp 0x198f9
leaq 0x140db1(%rip), %rdi    # 0x15a6a0
leaq 0x50(%rsp), %rdx
callq 0x14b86
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x42b0
leaq 0x6c16(%rip), %rsi      # 0x20523
leaq 0x8(%rsp), %rdi
callq 0x4090
movl %eax, 0x2c(%rsp)
testl %eax, %eax
je 0x19955
leaq 0x6c01(%rip), %rsi      # 0x20527
leaq 0x8(%rsp), %rdi
callq 0x4090
testl %eax, %eax
je 0x199e9
movq 0xb661(%rip), %rdi      # 0x24fa0
leaq 0x6bea(%rip), %rsi      # 0x20530
movl $0x10, %edx
callq 0x4290
jmp 0x19add
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 0x199f6
movq %r12, %rdi
leaq 0x6b37(%rip), %rsi      # 0x204be
callq 0x4090
testl %eax, %eax
je 0x199f6
movq %r13, 0x50(%rsp)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0xfcce
movq %rbp, %rdi
leaq 0x2cc7(%rip), %rsi      # 0x1c67b
callq 0x43e0
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
leaq 0x30(%rsp), %rdi
callq 0x40b0
movq 0x50(%rsp), %rdi
cmpq %r13, %rdi
je 0x19964
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4250
jmp 0x19964
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 0x19a6a
movq %r12, %rdi
movq %rbx, %rsi
callq 0x19374
movl %eax, %ebp
testw %ax, %ax
je 0x19a8f
movzwl %bp, %esi
movq %rbx, %rdi
callq 0x17b1c
movq 0x18(%rbx), %rax
movw %bp, 0x50(%rsp)
movq %rax, 0x58(%rsp)
movq 0x8(%r15), %rsi
cmpq 0x10(%r15), %rsi
je 0x19a5d
movups 0x50(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%r15)
jmp 0x19a00
movq %r15, %rdi
movq %r13, %rdx
callq 0x14b86
jmp 0x19a00
cmpl $0x0, 0x2c(%rsp)
jne 0x19add
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x16640
leaq 0x50(%rsp), %rsi
movq %rbx, %rdi
callq 0x16550
jmp 0x19add
movq 0xb50a(%rip), %rdi      # 0x24fa0
leaq 0x6a27(%rip), %rsi      # 0x204c4
movl $0x14, %edx
callq 0x4290
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0xb4e8(%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 0x18888
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x19af9
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4250
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x19b15
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 0x19b53
jmp 0x19b53
jmp 0x19b53
jmp 0x19b53
jmp 0x19b53
jmp 0x19b35
jmp 0x19b53
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %r13, %rdi
je 0x19b56
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4250
jmp 0x19b56
jmp 0x19b53
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x19b72
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4250
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x19b8e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4250
movq %rbx, %rdi
callq 0x43b0