// File: StanHash[P]nesdump/nesdump.cc
// Function: parse_item(std::basic_string_view<char, std::char_traits<char>>)
Item parse_item(std::string_view item_str)
{
    std::size_t const colon_pos = item_str.find_first_of(':');

    std::string_view const item_name = (colon_pos == std::string_view::npos)
        ? item_str
        : item_str.substr(0, colon_pos);

    std::string_view const item_part = (colon_pos == std::string_view::npos)
        ? ""
        : item_str.substr(colon_pos+1);

    if (item_name.compare("info") == 0)
    {
        Item result = ItemInfo {};
        return result;
    }

    if (item_name.compare("prg") == 0)
    {
        int bank = -1;

        if (!item_part.empty())
            bank = std::stoi(std::string { item_part }, nullptr, 0);

        Item result = ItemPrg { bank };
        return result;
    }

    if (item_name.compare("chr") == 0)
    {
        int bank = -1;

        if (!item_part.empty())
            bank = std::stoi(std::string { item_part }, nullptr, 0);

        Item result = ItemChr { bank };
        return result;
    }

    Item result = ItemError {};
    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x18(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x18(%rbp), %rdi
movl $0x3a, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x32a0
movq %rax, -0x20(%rbp)
cmpq $-0x1, -0x20(%rbp)
jne 0x2472
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x248b
movq -0x20(%rbp), %rdx
leaq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x32d0
movq %rax, -0x30(%rbp)
movq %rdx, -0x28(%rbp)
cmpq $-0x1, -0x20(%rbp)
jne 0x24a4
leaq -0x40(%rbp), %rdi
leaq 0x3c2b(%rip), %rsi      # 0x60c8
callq 0x3360
jmp 0x24c4
movq -0x20(%rbp), %rsi
addq $0x1, %rsi
leaq -0x18(%rbp), %rdi
movq $-0x1, %rdx
callq 0x32d0
movq %rax, -0x40(%rbp)
movq %rdx, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq 0x3b35(%rip), %rsi      # 0x6004
callq 0x33b0
cmpl $0x0, %eax
jne 0x24eb
leaq -0x8(%rbp), %rdi
leaq -0x41(%rbp), %rsi
callq 0x33f0
jmp 0x26bd
leaq -0x30(%rbp), %rdi
leaq 0x3b13(%rip), %rsi      # 0x6009
callq 0x33b0
cmpl $0x0, %eax
jne 0x25bd
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
leaq -0x40(%rbp), %rdi
callq 0x3420
testb $0x1, %al
jne 0x25a5
leaq -0x69(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x22c0
movq -0xc0(%rbp), %rdx
leaq -0x68(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3480
jmp 0x2542
xorl %edx, %edx
movl %edx, %esi
leaq -0x68(%rbp), %rdi
callq 0x3440
movl %eax, -0xc4(%rbp)
jmp 0x2557
movl -0xc4(%rbp), %eax
movl %eax, -0x48(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x2150
leaq -0x69(%rbp), %rdi
callq 0x21d0
jmp 0x25a5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x2597
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x2150
leaq -0x69(%rbp), %rdi
callq 0x21d0
jmp 0x26ca
movl -0x48(%rbp), %eax
movl %eax, -0x80(%rbp)
leaq -0x8(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x34f0
jmp 0x26bd
leaq -0x30(%rbp), %rdi
leaq 0x3a45(%rip), %rsi      # 0x600d
callq 0x33b0
cmpl $0x0, %eax
jne 0x26ad
movl $0xffffffff, -0x84(%rbp) # imm = 0xFFFFFFFF
leaq -0x40(%rbp), %rdi
callq 0x3420
testb $0x1, %al
jne 0x268f
leaq -0xa9(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x22c0
movq -0xd0(%rbp), %rdx
leaq -0xa8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3480
jmp 0x261d
xorl %edx, %edx
movl %edx, %esi
leaq -0xa8(%rbp), %rdi
callq 0x3440
movl %eax, -0xd4(%rbp)
jmp 0x2635
movl -0xd4(%rbp), %eax
movl %eax, -0x84(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x2150
leaq -0xa9(%rbp), %rdi
callq 0x21d0
jmp 0x268f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x2681
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x2150
leaq -0xa9(%rbp), %rdi
callq 0x21d0
jmp 0x26ca
movl -0x84(%rbp), %eax
movl %eax, -0xb0(%rbp)
leaq -0x8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x3520
jmp 0x26bd
leaq -0x8(%rbp), %rdi
leaq -0xb1(%rbp), %rsi
callq 0x3550
movq -0x8(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
movq -0x78(%rbp), %rdi
callq 0x22b0
nopw %cs:(%rax,%rax)