// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r14
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq %rsi, %rdi
callq 0x31e0
movq %rax, -0x58(%rbp)
pushq $0x2
popq %rsi
movq %r14, %rdi
callq 0x46fd
movl %eax, %r12d
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x471c
movl %eax, %r15d
testw %r12w, %r12w
jne 0x3cf7
movq 0x6305(%rip), %rdi      # 0x9ff0
leaq 0x238b(%rip), %rsi      # 0x607d
callq 0x3110
movzbl %r15b, %r15d
leal -0x1(%r15), %eax
movzwl %r12w, %ecx
movq %rcx, -0x50(%rbp)
cmpl $0x4, %eax
ja 0x3fc1
leaq 0x234d(%rip), %rcx      # 0x6064
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0x60
popq %rdi
callq 0x3120
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movaps %xmm0, 0x20(%rax)
movaps %xmm0, 0x30(%rax)
movaps %xmm0, 0x40(%rax)
movaps %xmm0, 0x50(%rax)
movaps %xmm0, 0x10(%rax)
leaq 0x50(%rax), %rcx
movq %rax, %rdx
addq $0x30, %rdx
leaq 0x59e4(%rip), %rsi      # 0x9738
movq %rsi, (%rax)
movq %rdx, 0x20(%rax)
movb $0x0, 0x30(%rax)
movq %rcx, 0x40(%rax)
andl $0x0, 0x50(%rax)
leaq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x4bb6
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x4c7e
leaq -0x40(%rbp), %rdi
callq 0x4a10
leaq -0x68(%rbp), %rdi
movq %rbx, %rsi
callq 0x473a
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x46df
movq -0x68(%rbp), %rcx
movl %eax, 0x10(%rcx)
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x4760
movq -0x68(%rbp), %rcx
movl %eax, 0x14(%rcx)
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x4760
movq -0x68(%rbp), %rsi
movl %eax, 0x18(%rsi)
addq $0x20, %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x339d
testb %al, %al
je 0x3e08
leaq -0x48(%rbp), %rdi
pushq $0x1
popq %rdx
movq %r14, %rsi
callq 0x3444
movq -0x68(%rbp), %rdi
addq $0x40, %rdi
leaq -0x48(%rbp), %r13
movq %r13, %rsi
callq 0x3210
movq %r13, %rdi
callq 0x3030
leaq -0x60(%rbp), %rdi
jmp 0x40a4
pushq $0x20
popq %rdi
callq 0x3120
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movaps %xmm0, 0x10(%rax)
leaq 0x5b36(%rip), %rcx      # 0x9960
movq %rcx, (%rax)
leaq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x55f0
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x56b8
leaq -0x40(%rbp), %rdi
callq 0x4a10
leaq -0x48(%rbp), %rdi
movq %rbx, %rsi
callq 0x48cd
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x4760
movq -0x48(%rbp), %rcx
movl %eax, 0x10(%rcx)
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x4760
movq -0x48(%rbp), %rcx
movl %eax, 0x14(%rcx)
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x47f0
leaq -0x40(%rbp), %rdi
movq -0x8(%rdi), %rcx
movq %rax, 0x18(%rcx)
jmp 0x40a4
pushq $0x18
popq %rdi
callq 0x3120
andq $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
leaq 0x5a74(%rip), %rcx      # 0x9928
movq %rcx, (%rax)
leaq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x54ee
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x55b6
leaq -0x40(%rbp), %rdi
callq 0x4a10
leaq -0x48(%rbp), %rdi
movq %rbx, %rsi
callq 0x48a7
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x4760
leaq -0x40(%rbp), %rdi
movq -0x8(%rdi), %rcx
movl %eax, 0x10(%rcx)
jmp 0x40a4
movq 0x60ca(%rip), %rdi      # 0x9fd0
movq (%rdi), %rax
movq -0x18(%rax), %rax
movl 0x18(%rdi,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%rdi,%rax)
movq -0x58(%rbp), %rsi
callq 0x31d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq %rax, %rdi
movq -0x50(%rbp), %rsi
callq 0x31c0
leaq 0x21a2(%rip), %rsi      # 0x60ee
movq %rax, %rdi
callq 0x3110
movq %rax, %rdi
callq 0x30c0
pushq $0x18
popq %rdi
callq 0x3120
andq $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
leaq 0x5a22(%rip), %rcx      # 0x9998
movq %rcx, (%rax)
leaq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x56f2
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x57c0
leaq -0x40(%rbp), %rdi
callq 0x4a10
leaq -0x48(%rbp), %rdi
movq %rbx, %rsi
callq 0x48f3
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x4919
leaq -0x40(%rbp), %rdi
movq -0x8(%rdi), %rcx
movb %al, 0x10(%rcx)
jmp 0x40a4
movq 0x6028(%rip), %r13      # 0x9ff0
leaq 0x20f8(%rip), %rsi      # 0x60c7
movq %r13, %rdi
callq 0x3110
movq %rax, %rdi
movl %r15d, %esi
callq 0x31c0
movq %rax, %rdi
callq 0x30c0
movq (%r13), %rax
movq -0x18(%rax), %rax
movl 0x18(%r13,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%r13,%rax)
leaq 0x20e3(%rip), %rsi      # 0x60ec
movq %r13, %rdi
callq 0x3110
movq %rax, %rdi
movq -0x58(%rbp), %rsi
callq 0x31d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
leaq 0x20b7(%rip), %rsi      # 0x60f0
movq %rax, %rdi
callq 0x3110
movq %rax, %rdi
movq -0x50(%rbp), %rsi
callq 0x31c0
leaq 0x2024(%rip), %rsi      # 0x6078
movq %rax, %rdi
callq 0x3110
movzwl %r15w, %esi
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
callq 0x30c0
pushq $0x10
popq %rdi
callq 0x3120
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
leaq 0x56fb(%rip), %rcx      # 0x9780
movq %rcx, (%rax)
leaq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x53ec
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x54b4
leaq -0x40(%rbp), %rdi
callq 0x4a10
movq (%rbx), %rax
movw %r12w, 0x8(%rax)
movl %r15d, 0xc(%rax)
movq %r14, %rdi
callq 0x31e0
movq -0x58(%rbp), %rcx
movq -0x50(%rbp), %rdx
addl %edx, %ecx
addl $0x2, %ecx
movslq %ecx, %rsi
cmpq %rsi, %rax
jge 0x40dc
movq %r14, %rdi
xorl %edx, %edx
callq 0x3150
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4107
jmp 0x40fe
jmp 0x40fe
jmp 0x411b
jmp 0x411b
jmp 0x411b
jmp 0x411b
jmp 0x411b
movq %rax, %r14
leaq -0x40(%rbp), %rdi
jmp 0x410e
movq %rax, %r14
leaq -0x60(%rbp), %rdi
callq 0x4a10
jmp 0x411e
jmp 0x411b
jmp 0x411b
jmp 0x411b
movq %rax, %r14
addq $0x8, %rbx
movq %rbx, %rdi
callq 0x4a10
movq %r14, %rdi
callq 0x31f0