// File: /workspace/github_cpp_makefile_star2_O3/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 0x31f0
movq %rax, -0x60(%rbp)
leaq -0x50(%rbp), %rsi
movl $0x2, %edx
movq %r14, %rdi
callq 0x3160
leaq -0x50(%rbp), %rsi
movzwl (%rsi), %eax
movw %ax, -0x2a(%rbp)
movl $0x1, %edx
movq %r14, %rdi
callq 0x3160
movzbl -0x50(%rbp), %eax
movq %rax, -0x68(%rbp)
cmpw $0x0, -0x2a(%rbp)
jne 0x4009
movq 0x5ff8(%rip), %rdi      # 0x9ff0
leaq 0x207e(%rip), %rsi      # 0x607d
movl $0x49, %edx
callq 0x3150
movzwl -0x2a(%rbp), %eax
movq %rax, -0x58(%rbp)
movq -0x68(%rbp), %rax
decl %eax
cmpl $0x4, %eax
ja 0x4266
leaq 0x203d(%rip), %rcx      # 0x6064
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x60, %edi
callq 0x3130
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 0x56d2(%rip), %rsi      # 0x9738
movq %rsi, (%rax)
movq %rdx, 0x20(%rax)
movb $0x0, 0x30(%rax)
movq %rcx, 0x40(%rax)
movl $0x0, 0x50(%rax)
leaq -0x48(%rbp), %rdi
movq %rax, -0x8(%rdi)
movq %rax, %rsi
callq 0x5038
movq -0x50(%rbp), %r15
movq -0x48(%rbp), %r13
movq %r15, (%rbx)
movq %r13, 0x8(%rbx)
testq %r13, %r13
je 0x440e
movq 0x5f1d(%rip), %rax      # 0x9fc8
cmpb $0x0, (%rax)
je 0x4409
incl 0x8(%r13)
jmp 0x440e
movl $0x20, %edi
callq 0x3130
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movaps %xmm0, 0x10(%rax)
leaq 0x5888(%rip), %rcx      # 0x9960
movq %rcx, (%rax)
leaq -0x48(%rbp), %rdi
movq %rax, -0x8(%rdi)
movq %rax, %rsi
callq 0x5740
movq -0x50(%rbp), %r12
movq -0x48(%rbp), %r15
movq %r12, (%rbx)
movq %r15, 0x8(%rbx)
testq %r15, %r15
je 0x43ba
movq 0x5ebe(%rip), %rax      # 0x9fc8
cmpb $0x0, (%rax)
je 0x43b5
incl 0x8(%r15)
jmp 0x43ba
movl $0x18, %edi
callq 0x3130
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movq $0x0, 0x10(%rax)
leaq 0x57ed(%rip), %rcx      # 0x9928
movq %rcx, (%rax)
leaq -0x48(%rbp), %rdi
movq %rax, -0x8(%rdi)
movq %rax, %rsi
callq 0x568c
movq -0x50(%rbp), %r12
movq -0x48(%rbp), %r15
movq %r12, (%rbx)
movq %r15, 0x8(%rbx)
testq %r15, %r15
je 0x44ba
movq 0x5e5b(%rip), %rax      # 0x9fc8
cmpb $0x0, (%rax)
je 0x44b5
incl 0x8(%r15)
jmp 0x44ba
movq 0x5e4a(%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 -0x60(%rbp), %rsi
callq 0x31e0
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 -0x58(%rbp), %rsi
callq 0x30e0
movq %rax, %r15
leaq 0x1f1f(%rip), %rsi      # 0x60ee
movl $0x1, %edx
movq %rax, %rdi
callq 0x3150
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3120
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movl $0x18, %edi
callq 0x3130
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movq $0x0, 0x10(%rax)
leaq 0x5776(%rip), %rcx      # 0x9998
movq %rcx, (%rax)
leaq -0x48(%rbp), %rdi
movq %rax, -0x8(%rdi)
movq %rax, %rsi
callq 0x57f4
movq -0x50(%rbp), %r12
movq -0x48(%rbp), %r15
movq %r12, (%rbx)
movq %r15, 0x8(%rbx)
testq %r15, %r15
je 0x44da
movq 0x5d74(%rip), %rax      # 0x9fc8
cmpb $0x0, (%rax)
je 0x44d5
incl 0x8(%r15)
jmp 0x44da
movq 0x5d83(%rip), %rdi      # 0x9ff0
leaq 0x1e53(%rip), %rsi      # 0x60c7
movl $0x24, %edx
callq 0x3150
movl -0x68(%rbp), %r13d
movq 0x5d67(%rip), %r15      # 0x9ff0
movq %r15, %rdi
movq %r13, %rsi
callq 0x30e0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3120
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq (%r15), %rax
movq -0x18(%rax), %rax
movl 0x18(%r15,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%r15,%rax)
leaq 0x1e10(%rip), %rsi      # 0x60ec
movl $0x3, %edx
movq %r15, %rdi
callq 0x3150
movq 0x5d00(%rip), %rdi      # 0x9ff0
movq -0x60(%rbp), %rsi
callq 0x31e0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rax
movl 0x18(%r15,%rax), %ecx
andl $-0x4b, %ecx
orl $0x2, %ecx
movl %ecx, 0x18(%r15,%rax)
leaq 0x1dd6(%rip), %rsi      # 0x60f0
movl $0x4, %edx
movq %r15, %rdi
callq 0x3150
movq %r15, %rdi
movq -0x58(%rbp), %rsi
callq 0x30e0
movq %rax, %r15
leaq 0x1d3b(%rip), %rsi      # 0x6078
movl $0x4, %edx
movq %rax, %rdi
callq 0x3150
movq %r15, %rdi
movq %r13, %rsi
callq 0x30e0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3120
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movl $0x10, %edi
callq 0x3130
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
leaq 0x53ea(%rip), %rcx      # 0x9780
movq %rcx, (%rax)
leaq -0x48(%rbp), %rdi
movq %rax, -0x8(%rdi)
movq %rax, %rsi
callq 0x55d8
movups -0x50(%rbp), %xmm0
movups %xmm0, (%rbx)
jmp 0x4500
lock
incl 0x8(%r15)
leaq -0x50(%rbp), %rsi
movl $0x4, %edx
movq %r14, %rdi
callq 0x3160
leaq -0x50(%rbp), %rsi
movl (%rsi), %eax
movl %eax, 0x10(%r12)
movl $0x4, %edx
movq %r14, %rdi
callq 0x3160
leaq -0x50(%rbp), %rsi
movl (%rsi), %eax
movl %eax, 0x14(%r12)
movl $0x8, %edx
movq %r14, %rdi
callq 0x3160
movq -0x50(%rbp), %rax
movq %rax, 0x18(%r12)
jmp 0x44f3
lock
incl 0x8(%r13)
leaq -0x50(%rbp), %rsi
movl $0x4, %edx
movq %r14, %rdi
callq 0x3160
leaq -0x50(%rbp), %rsi
movl (%rsi), %eax
movl %eax, 0x10(%r15)
movl $0x4, %edx
movq %r14, %rdi
callq 0x3160
leaq -0x50(%rbp), %rsi
movl (%rsi), %eax
movl %eax, 0x14(%r15)
movl $0x4, %edx
movq %r14, %rdi
callq 0x3160
movl -0x50(%rbp), %eax
movl %eax, 0x18(%r15)
leaq 0x20(%r15), %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0x33bd
testb %al, %al
je 0x44ab
leaq -0x50(%rbp), %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x3483
addq $0x40, %r15
leaq -0x50(%rbp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x3220
movq (%r12), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x44ab
movq -0x40(%rbp), %rax
leaq 0x4(,%rax,4), %rsi
callq 0x3140
testq %r13, %r13
je 0x4500
movq %r13, %rdi
jmp 0x44fb
lock
incl 0x8(%r15)
leaq -0x50(%rbp), %rsi
movl $0x4, %edx
movq %r14, %rdi
callq 0x3160
movl -0x50(%rbp), %eax
movl %eax, 0x10(%r12)
jmp 0x44f3
lock
incl 0x8(%r15)
leaq -0x50(%rbp), %rsi
movl $0x1, %edx
movq %r14, %rdi
callq 0x3160
movb -0x50(%rbp), %al
movb %al, 0x10(%r12)
testq %r15, %r15
je 0x4500
movq %r15, %rdi
callq 0x4e72
movq (%rbx), %rax
movzwl -0x2a(%rbp), %ecx
movw %cx, 0x8(%rax)
movq -0x68(%rbp), %rcx
movl %ecx, 0xc(%rax)
movq %r14, %rdi
callq 0x31f0
movq -0x60(%rbp), %rcx
movq -0x58(%rbp), %rdx
addl %edx, %ecx
addl $0x2, %ecx
movslq %ecx, %rsi
cmpq %rsi, %rax
jge 0x4539
movq %r14, %rdi
xorl %edx, %edx
callq 0x3170
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4568
jmp 0x455b
jmp 0x455b
jmp 0x4580
jmp 0x4580
jmp 0x4580
jmp 0x4580
jmp 0x4580
movq %rax, %r14
testq %r15, %r15
je 0x4583
movq %r15, %rdi
jmp 0x4573
movq %rax, %r14
testq %r13, %r13
je 0x4583
movq %r13, %rdi
callq 0x4e72
jmp 0x4583
jmp 0x4580
jmp 0x4580
jmp 0x4580
movq %rax, %r14
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x4591
callq 0x4e72
movq %r14, %rdi
callq 0x3200