// File: instance01[P]chromium-snss-parse/examples/../snss-parse-lib.hpp
// Function: read_next_tab_command(std::basic_ifstream<char, std::char_traits<char>>&)
std::shared_ptr<Command> read_next_tab_command(std::ifstream& f) {
    std::shared_ptr<Command> ret;
    int prev = f.tellg();
    uint16_t size = read_arbitrary<uint16_t>(f, 2);
    uint8_t type_id = read_arbitrary<uint8_t>(f, 1);

    if (0 == size) {
        std::cerr << "Error: Encountered command with size 0. This can indicate a corrupt file.";
    }

    switch(type_id) {
        case 1: // CommandUpdateTabNavigation
        {
            // TODO Copied from read_next_session_command
            ret = std::shared_ptr<CommandUpdateTabNavigation>(new CommandUpdateTabNavigation());
            std::shared_ptr<CommandUpdateTabNavigation> ret2 = std::static_pointer_cast<CommandUpdateTabNavigation>(ret);
            ret2->pickle_size = read_arbitrary<uint32_t>(f, 4);
            ret2->tabid = read_arbitrary<int32_t>(f, 4);
            ret2->index = read_arbitrary<int32_t>(f, 4);
            if (read_string(f, ret2->url, true))
                ret2->title = read_string16(f, true);
            // TODO Add missing stuff
            break;
        }
        case 2: // CommandRestoredEntry
        {
            ret = std::shared_ptr<CommandRestoredEntry>(new CommandRestoredEntry());
            std::shared_ptr<CommandRestoredEntry> ret2 = std::static_pointer_cast<CommandRestoredEntry>(ret);
            ret2->entry_id = read_arbitrary<int32_t>(f, 4);
            break;
        }
        case 4: // CommandSelectedNavigationInTab
        {
            ret = std::shared_ptr<CommandSelectedNavigationInTab>(new CommandSelectedNavigationInTab());
            std::shared_ptr<CommandSelectedNavigationInTab> ret2 = std::static_pointer_cast<CommandSelectedNavigationInTab>(ret);
            ret2->tabid = read_arbitrary<int32_t>(f, 4);
            ret2->index = read_arbitrary<int32_t>(f, 4);
            ret2->timestamp = read_arbitrary<int64_t>(f, 8); // TODO First probe for next command
            break;
        }
        case 5: // CommandPinnedState
        {
            std::cout << std::hex << prev << std::dec << size << " " << std::endl;
            ret = std::shared_ptr<CommandPinnedState>(new CommandPinnedState());
            std::shared_ptr<CommandPinnedState> ret2 = std::static_pointer_cast<CommandPinnedState>(ret);
            ret2->pinned = read_arbitrary<bool>(f, 1);
            break;
        }
        default:
        {
            std::cerr << "Warning: Encountered unsupported id " << static_cast<uint16_t>(type_id) << std::endl;
            std::cerr << std::hex << "P: " << prev << std::dec << " S: " << size << " T: " << static_cast<uint16_t>(type_id) << std::endl;
            ret = std::shared_ptr<Command>(new Command());
        }
    }

    ret->size = size;
    ret->type = type_id;

    // Finish reading the command in case we skipped stuff
    prev += size + 2L;
    if (f.tellg() < prev) {
        f.seekg(prev);
    }
    return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
movq %rdi, -0x128(%rbp)
movq %rdi, %rax
movq %rax, -0x120(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, -0x11(%rbp)
callq 0x5b90
movq -0x10(%rbp), %rdi
callq 0x3240
movq %rdx, -0x118(%rbp)
movq %rax, -0x110(%rbp)
jmp 0x46a6
movq -0x118(%rbp), %rax
movq -0x110(%rbp), %rcx
movq %rcx, -0x28(%rbp)
movq %rax, -0x20(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x5ad0
movq %rax, -0x130(%rbp)
jmp 0x46ce
movq -0x130(%rbp), %rax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movl $0x2, %esi
callq 0x5af0
movw %ax, -0x132(%rbp)
jmp 0x46ef
movw -0x132(%rbp), %ax
movw %ax, -0x36(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x5b60
movb %al, -0x133(%rbp)
jmp 0x4710
movb -0x133(%rbp), %al
movb %al, -0x37(%rbp)
movzwl -0x36(%rbp), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x474b
movq 0xd8c6(%rip), %rdi      # 0x11ff0
leaq 0x694c(%rip), %rsi      # 0xb07d
callq 0x3130
jmp 0x4738
jmp 0x474b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4f24
movzbl -0x37(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x140(%rbp)
subl $0x4, %eax
ja 0x4c88
movq -0x140(%rbp), %rax
leaq 0x68f3(%rip), %rcx      # 0xb064
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x60, %edi
callq 0x3140
movq %rax, -0x148(%rbp)
jmp 0x478d
movq -0x148(%rbp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rdi)
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
callq 0x5bb0
movq -0x148(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x5c00
jmp 0x47c5
movq -0x128(%rbp), %rdi
leaq -0x48(%rbp), %rsi
movq %rsi, -0x158(%rbp)
callq 0x5c30
movq -0x158(%rbp), %rdi
callq 0x5c60
movq -0x128(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x5c80
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x5aa0
movl %eax, -0x14c(%rbp)
jmp 0x480e
leaq -0x58(%rbp), %rdi
callq 0x5cd0
movl -0x14c(%rbp), %ecx
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x5cf0
movl %eax, -0x15c(%rbp)
jmp 0x4836
leaq -0x58(%rbp), %rdi
callq 0x5cd0
movl -0x15c(%rbp), %ecx
movl %ecx, 0x14(%rax)
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x5cf0
movl %eax, -0x160(%rbp)
jmp 0x485e
leaq -0x58(%rbp), %rdi
movq %rdi, -0x178(%rbp)
callq 0x5cd0
movl -0x160(%rbp), %ecx
movq -0x178(%rbp), %rdi
movl %ecx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x170(%rbp)
callq 0x5cd0
movq -0x170(%rbp), %rdi
movq %rax, %rsi
addq $0x20, %rsi
movl $0x1, %edx
callq 0x3460
movb %al, -0x161(%rbp)
jmp 0x48ae
movb -0x161(%rbp), %al
testb $0x1, %al
jne 0x48ba
jmp 0x490c
movq -0x10(%rbp), %rsi
leaq -0x78(%rbp), %rdi
movl $0x1, %edx
callq 0x35b0
jmp 0x48ce
leaq -0x58(%rbp), %rdi
callq 0x5cd0
movq %rax, %rdi
addq $0x40, %rdi
leaq -0x78(%rbp), %rsi
callq 0x3270
leaq -0x78(%rbp), %rdi
callq 0x3210
jmp 0x490c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x5c60
jmp 0x4f24
leaq -0x58(%rbp), %rdi
callq 0x5c60
jmp 0x4e16
movl $0x18, %edi
callq 0x3140
movq %rax, -0x180(%rbp)
jmp 0x492d
movq -0x180(%rbp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
callq 0x66c0
movq -0x180(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0x6700
jmp 0x495c
movq -0x128(%rbp), %rdi
leaq -0x88(%rbp), %rsi
movq %rsi, -0x190(%rbp)
callq 0x6730
movq -0x190(%rbp), %rdi
callq 0x6760
movq -0x128(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0x6780
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x5cf0
movl %eax, -0x184(%rbp)
jmp 0x49ab
leaq -0x98(%rbp), %rdi
callq 0x67d0
movl -0x184(%rbp), %ecx
movl %ecx, 0x10(%rax)
leaq -0x98(%rbp), %rdi
callq 0x6760
jmp 0x4e16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x6760
jmp 0x4f24
movl $0x20, %edi
callq 0x3140
movq %rax, -0x198(%rbp)
jmp 0x4a01
movq -0x198(%rbp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
callq 0x67f0
movq -0x198(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x6830
jmp 0x4a2c
movq -0x128(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
movq %rsi, -0x1a8(%rbp)
callq 0x6860
movq -0x1a8(%rbp), %rdi
callq 0x6890
movq -0x128(%rbp), %rsi
leaq -0xb8(%rbp), %rdi
callq 0x68b0
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x5cf0
movl %eax, -0x19c(%rbp)
jmp 0x4a7b
leaq -0xb8(%rbp), %rdi
callq 0x6900
movl -0x19c(%rbp), %ecx
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x5cf0
movl %eax, -0x1ac(%rbp)
jmp 0x4aa6
leaq -0xb8(%rbp), %rdi
callq 0x6900
movl -0x1ac(%rbp), %ecx
movl %ecx, 0x14(%rax)
movq -0x10(%rbp), %rdi
movl $0x8, %esi
callq 0x60b0
movq %rax, -0x1b8(%rbp)
jmp 0x4ad2
leaq -0xb8(%rbp), %rdi
callq 0x6900
movq -0x1b8(%rbp), %rcx
movq %rcx, 0x18(%rax)
leaq -0xb8(%rbp), %rdi
callq 0x6890
jmp 0x4e16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x6890
jmp 0x4f24
movq 0xd4b2(%rip), %rdi      # 0x11fd0
leaq 0x1a7b(%rip), %rsi      # 0x65a0
callq 0x3070
movq %rax, -0x1c0(%rbp)
jmp 0x4b33
movq -0x1c0(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x3230
movq %rax, -0x1c8(%rbp)
jmp 0x4b4b
movq -0x1c8(%rbp), %rdi
leaq 0x1a77(%rip), %rsi      # 0x65d0
callq 0x3070
movq %rax, -0x1d0(%rbp)
jmp 0x4b67
movq -0x1d0(%rbp), %rdi
movzwl -0x36(%rbp), %esi
callq 0x3220
movq %rax, -0x1d8(%rbp)
jmp 0x4b80
movq -0x1d8(%rbp), %rdi
leaq 0x6560(%rip), %rsi      # 0xb0ee
callq 0x3130
movq %rax, -0x1e0(%rbp)
jmp 0x4b9c
movq -0x1e0(%rbp), %rdi
movq 0xd40e(%rip), %rsi      # 0x11fb8
callq 0x3160
jmp 0x4bb1
movl $0x18, %edi
callq 0x3140
movq %rax, -0x1e8(%rbp)
jmp 0x4bc4
movq -0x1e8(%rbp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
callq 0x6920
movq -0x1e8(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
callq 0x6960
jmp 0x4bf3
movq -0x128(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
movq %rsi, -0x1f8(%rbp)
callq 0x6990
movq -0x1f8(%rbp), %rdi
callq 0x69c0
movq -0x128(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x69e0
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x6a30
movb %al, -0x1e9(%rbp)
jmp 0x4c42
leaq -0xd8(%rbp), %rdi
callq 0x6a60
movb -0x1e9(%rbp), %cl
andb $0x1, %cl
movb %cl, 0x10(%rax)
leaq -0xd8(%rbp), %rdi
callq 0x69c0
jmp 0x4e16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x69c0
jmp 0x4f24
movq 0xd361(%rip), %rdi      # 0x11ff0
leaq 0x6431(%rip), %rsi      # 0xb0c7
callq 0x3130
movq %rax, -0x200(%rbp)
jmp 0x4ca4
movq -0x200(%rbp), %rdi
movzbl -0x37(%rbp), %esi
callq 0x3220
movq %rax, -0x208(%rbp)
jmp 0x4cbd
movq -0x208(%rbp), %rdi
movq 0xd2ed(%rip), %rsi      # 0x11fb8
callq 0x3160
jmp 0x4cd2
movq 0xd317(%rip), %rdi      # 0x11ff0
leaq 0x18c0(%rip), %rsi      # 0x65a0
callq 0x3070
movq %rax, -0x210(%rbp)
jmp 0x4cee
movq -0x210(%rbp), %rdi
leaq 0x63f0(%rip), %rsi      # 0xb0ec
callq 0x3130
movq %rax, -0x218(%rbp)
jmp 0x4d0a
movq -0x218(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x3230
movq %rax, -0x220(%rbp)
jmp 0x4d22
movq -0x220(%rbp), %rdi
leaq 0x18a0(%rip), %rsi      # 0x65d0
callq 0x3070
movq %rax, -0x228(%rbp)
jmp 0x4d3e
movq -0x228(%rbp), %rdi
leaq 0x63a4(%rip), %rsi      # 0xb0f0
callq 0x3130
movq %rax, -0x230(%rbp)
jmp 0x4d5a
movq -0x230(%rbp), %rdi
movzwl -0x36(%rbp), %esi
callq 0x3220
movq %rax, -0x238(%rbp)
jmp 0x4d73
movq -0x238(%rbp), %rdi
leaq 0x62f7(%rip), %rsi      # 0xb078
callq 0x3130
movq %rax, -0x240(%rbp)
jmp 0x4d8f
movq -0x240(%rbp), %rdi
movzbl -0x37(%rbp), %esi
callq 0x3220
movq %rax, -0x248(%rbp)
jmp 0x4da8
movq -0x248(%rbp), %rdi
movq 0xd202(%rip), %rsi      # 0x11fb8
callq 0x3160
jmp 0x4dbd
movl $0x10, %edi
callq 0x3140
movq %rax, -0x250(%rbp)
jmp 0x4dd0
movq -0x250(%rbp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
callq 0x6600
movq -0x250(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x6620
jmp 0x4df7
movq -0x128(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x6650
leaq -0xe8(%rbp), %rdi
callq 0x6680
movq -0x128(%rbp), %rdi
movw -0x36(%rbp), %ax
movw %ax, -0x266(%rbp)
callq 0x66a0
movw -0x266(%rbp), %cx
movq -0x128(%rbp), %rdi
movw %cx, 0x8(%rax)
movzbl -0x37(%rbp), %eax
movl %eax, -0x264(%rbp)
callq 0x66a0
movl -0x264(%rbp), %ecx
movl %ecx, 0xc(%rax)
movzwl -0x36(%rbp), %edx
movl -0x18(%rbp), %eax
movl %eax, %ecx
movl %edx, %eax
leal 0x2(%rax,%rcx), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3240
movq %rdx, -0x260(%rbp)
movq %rax, -0x258(%rbp)
jmp 0x4e82
movq -0x260(%rbp), %rax
movq -0x258(%rbp), %rcx
movq %rcx, -0xf8(%rbp)
movq %rax, -0xf0(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x5ad0
movq %rax, -0x270(%rbp)
jmp 0x4eb3
movq -0x270(%rbp), %rax
movslq -0x18(%rbp), %rcx
cmpq %rcx, %rax
jge 0x4efe
movq -0x10(%rbp), %rax
movq %rax, -0x278(%rbp)
movslq -0x18(%rbp), %rsi
leaq -0x108(%rbp), %rdi
callq 0x5a60
jmp 0x4ee0
movq -0x278(%rbp), %rdi
movq -0x108(%rbp), %rsi
movq -0x100(%rbp), %rdx
callq 0x3180
jmp 0x4efc
jmp 0x4efe
movb $0x1, -0x11(%rbp)
testb $0x1, -0x11(%rbp)
jne 0x4f14
movq -0x128(%rbp), %rdi
callq 0x6680
movq -0x120(%rbp), %rax
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
movq -0x128(%rbp), %rdi
callq 0x6680
movq -0x30(%rbp), %rdi
callq 0x3250
nopl (%rax)