// File: 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:
subq $0xb48, %rsp            # imm = 0xB48
movq %rdi, 0xb40(%rsp)
movq %rsi, 0xb38(%rsp)
leaq 0xb18(%rsp), %rdi
callq 0x5390
leaq 0xaf8(%rsp), %rdi
callq 0x5390
movb $0x0, 0xaf5(%rsp)
leaq 0x242e80(%rip), %rsi    # 0x280ec0
leaq 0x5e8(%rsp), %rdi
callq 0x36550
jmp 0x3e04f
movq 0xb38(%rsp), %rdi
leaq 0x5e8(%rsp), %rsi
callq 0x363b0
jmp 0x3e066
leaq 0x1d86d3(%rip), %rdi    # 0x216740
callq 0x3ebe0
jmp 0x3e074
movq 0xb38(%rsp), %rdi
callq 0x308b0
movq %rax, 0x70(%rsp)
jmp 0x3e088
movq 0x70(%rsp), %rax
movq %rax, 0x5c0(%rsp)
leaq 0x753a(%rip), %rdi      # 0x455d6
leaq 0x5c0(%rsp), %rsi
callq 0x30870
movq %rdx, 0x60(%rsp)
movw %ax, 0x6e(%rsp)
jmp 0x3e0b5
movq 0x60(%rsp), %rax
movw 0x6e(%rsp), %cx
movw %cx, 0x5c8(%rsp)
movq %rax, 0x5d0(%rsp)
leaq 0x1d866a(%rip), %rdi    # 0x216740
leaq 0x5c8(%rsp), %rsi
callq 0x30840
jmp 0x3e0e5
movq 0xb40(%rsp), %rdi
leaq 0xb18(%rsp), %rsi
callq 0x5330
jmp 0x3e0fc
leaq 0x7414(%rip), %rsi      # 0x45517
leaq 0xb18(%rsp), %rdi
callq 0x35540
movb %al, 0x5f(%rsp)
jmp 0x3e116
movb 0x5f(%rsp), %al
testb $0x1, %al
jne 0x3e123
jmp 0x3e225
jmp 0x3e125
movq 0xb40(%rsp), %rdi
leaq 0xb18(%rsp), %rsi
callq 0x5330
movq %rax, 0x50(%rsp)
jmp 0x3e141
movq 0x50(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x5320
movb %al, 0x4f(%rsp)
jmp 0x3e15b
movb 0x4f(%rsp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0x4e(%rsp)
jne 0x3e16c
jmp 0x3e190
leaq 0x733f(%rip), %rsi      # 0x454b2
leaq 0xb18(%rsp), %rdi
callq 0x3ed50
movb %al, 0x4d(%rsp)
jmp 0x3e186
movb 0x4d(%rsp), %al
movb %al, 0x4e(%rsp)
jmp 0x3e190
movb 0x4e(%rsp), %al
testb $0x1, %al
jne 0x3e19d
jmp 0x3e223
leaq 0x2ebf(%rip), %rdx      # 0x41063
leaq 0x5a0(%rsp), %rdi
leaq 0xb18(%rsp), %rsi
callq 0x3ed80
jmp 0x3e1bb
leaq 0xaf8(%rsp), %rdi
leaq 0x5a0(%rsp), %rsi
callq 0x5340
jmp 0x3e1d2
leaq 0x5a0(%rsp), %rdi
callq 0x5538
jmp 0x3e125
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x5e0(%rsp)
movl %eax, 0x5dc(%rsp)
jmp 0x3e46a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x5e0(%rsp)
movl %eax, 0x5dc(%rsp)
leaq 0x5a0(%rsp), %rdi
callq 0x5538
jmp 0x3e46a
jmp 0x3e291
leaq 0x72ef(%rip), %rsi      # 0x4551b
leaq 0xb18(%rsp), %rdi
callq 0x35540
movb %al, 0x4c(%rsp)
jmp 0x3e23f
movb 0x4c(%rsp), %al
testb $0x1, %al
jne 0x3e249
jmp 0x3e26a
movb $0x1, 0xaf5(%rsp)
movq 0xb40(%rsp), %rdi
leaq 0xb18(%rsp), %rsi
callq 0x5330
jmp 0x3e268
jmp 0x3e28f
movq 0x12d47(%rip), %rdi     # 0x50fb8
leaq 0x72ac(%rip), %rsi      # 0x45524
callq 0x5290
jmp 0x3e27f
movl $0x1, 0x59c(%rsp)
jmp 0x3e448
jmp 0x3e291
jmp 0x3e293
movq 0xb40(%rsp), %rdi
leaq 0xb18(%rsp), %rsi
callq 0x5330
movq %rax, 0x40(%rsp)
jmp 0x3e2af
movq 0x40(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x5320
movb %al, 0x3f(%rsp)
jmp 0x3e2c9
movb 0x3f(%rsp), %al
testb $0x1, %al
jne 0x3e2d6
jmp 0x3e409
movq 0xb38(%rsp), %rsi
leaq 0xb18(%rsp), %rdi
callq 0x3d890
movw %ax, 0x3c(%rsp)
jmp 0x3e2f2
movw 0x3c(%rsp), %ax
movw %ax, 0xaf6(%rsp)
movzwl 0xaf6(%rsp), %eax
cmpl $0x0, %eax
jne 0x3e379
movq 0x12ca5(%rip), %rdi     # 0x50fb8
leaq 0x719e(%rip), %rsi      # 0x454b8
callq 0x5290
movq %rax, 0x30(%rsp)
jmp 0x3e326
movq 0x30(%rsp), %rdi
leaq 0xb18(%rsp), %rsi
callq 0x5220
movq %rax, 0x28(%rsp)
jmp 0x3e33f
movq 0x28(%rsp), %rdi
movl $0xa, %esi
callq 0x5300
movq %rax, 0x20(%rsp)
jmp 0x3e355
movq 0x20(%rsp), %rdi
movq 0xb38(%rsp), %rsi
callq 0x38ae0
jmp 0x3e369
movl $0x1, 0x59c(%rsp)
jmp 0x3e448
movq 0xb38(%rsp), %rdi
movzwl 0xaf6(%rsp), %esi
callq 0x38340
jmp 0x3e390
movq 0xb38(%rsp), %rdi
callq 0x308b0
movq %rax, 0x18(%rsp)
jmp 0x3e3a4
movq 0x18(%rsp), %rax
movq %rax, 0x580(%rsp)
leaq 0xaf6(%rsp), %rdi
leaq 0x580(%rsp), %rsi
callq 0x356c0
movq %rdx, 0x8(%rsp)
movw %ax, 0x16(%rsp)
jmp 0x3e3d2
movq 0x8(%rsp), %rax
movw 0x16(%rsp), %cx
movw %cx, 0x588(%rsp)
movq %rax, 0x590(%rsp)
leaq 0x1d834d(%rip), %rdi    # 0x216740
leaq 0x588(%rsp), %rsi
callq 0x30840
jmp 0x3e402
jmp 0x3e404
jmp 0x3e293
testb $0x1, 0xaf5(%rsp)
jne 0x3e43d
leaq 0x78(%rsp), %rdi
leaq 0xaf8(%rsp), %rsi
callq 0x36550
jmp 0x3e427
movq 0xb38(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x363b0
jmp 0x3e43b
jmp 0x3e43d
movl $0x0, 0x59c(%rsp)
leaq 0xaf8(%rsp), %rdi
callq 0x5538
leaq 0xb18(%rsp), %rdi
callq 0x5538
addq $0xb48, %rsp            # imm = 0xB48
retq
leaq 0xaf8(%rsp), %rdi
callq 0x5538
leaq 0xb18(%rsp), %rdi
callq 0x5538
movq 0x5e0(%rsp), %rdi
callq 0x54b0
nopw %cs:(%rax,%rax)