// File: /workspace/github_cpp_makefile_star2_O2/instance01[P]chromium-snss-parse/examples/../snss-parse-lib.hpp
// Function: read_next_session_command(std::basic_ifstream<char, std::char_traits<char>>&)
std::shared_ptr<Command> read_next_session_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.";
    }

    // See https://0x1.pl/s/33 for all command ids
    switch(type_id) {
        case 6: // CommandUpdateTabNavigation
        {
            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 0: // CommandSetTabWindow
        case 2: // CommandSetTabIndexInWindow
        case 5: // CommandTabNavigationPathPrunedFromBack
        case 7: // CommandSetSelectedNavigationIndex
        case 8: // CommandSetSelectedTabInIndex
        case 9: // CommandSetWindowType
        case 12: // CommandSetPinnedState (TODO works, but we should read a bool here, not int!)
        {
            ret = std::shared_ptr<IDAndIndex>(new IDAndIndex());
            std::shared_ptr<IDAndIndex> ret2 = std::static_pointer_cast<IDAndIndex>(ret);
            //IDAndIndex & cmd = (IDAndIndex &) ret;
            ret2->id = read_arbitrary<uint32_t>(f, 4);
            ret2->index = read_arbitrary<int32_t>(f, 4);
            break;
        }
        case 14: // CommandSetWindowBounds3
        {
            ret = std::shared_ptr<CommandSetWindowBounds3>(new CommandSetWindowBounds3());
            std::shared_ptr<CommandSetWindowBounds3> ret2 = std::static_pointer_cast<CommandSetWindowBounds3>(ret);
            ret2->window_id = read_arbitrary<int32_t>(f, 4);
            ret2->x = read_arbitrary<int32_t>(f, 4);
            ret2->y = read_arbitrary<int32_t>(f, 4);
            ret2->width = read_arbitrary<int32_t>(f, 4);
            ret2->height = read_arbitrary<int32_t>(f, 4);
            ret2->show_state = read_arbitrary<int32_t>(f, 4);
            break;
        }
        case 16: // CommandTabClosed
        {
            ret = std::shared_ptr<CommandTabClosed>(new CommandTabClosed());
            std::shared_ptr<CommandTabClosed> ret2 = std::static_pointer_cast<CommandTabClosed>(ret);
            ret2->id = read_arbitrary<int32_t>(f, 4);
            ret2->UNKNOWN_0 = read_arbitrary<int32_t>(f, 4); // TODO
            ret2->close_time = read_arbitrary<int64_t>(f, 8);
            break;
        }
        case 17: // CommandWindowClosed
        {
            ret = std::shared_ptr<CommandWindowClosed>(new CommandWindowClosed());
            std::shared_ptr<CommandWindowClosed> ret2 = std::static_pointer_cast<CommandWindowClosed>(ret);
            ret2->id = read_arbitrary<int32_t>(f, 4);
            ret2->UNKNOWN_0 = read_arbitrary<int32_t>(f, 4); // TODO
            ret2->close_time = read_arbitrary<int64_t>(f, 8);
            break;
        }
        case 19: // CommandSessionStorageAssociated
        {
            ret = std::shared_ptr<CommandSessionStorageAssociated>(new CommandSessionStorageAssociated());
            std::shared_ptr<CommandSessionStorageAssociated> ret2 = std::static_pointer_cast<CommandSessionStorageAssociated>(ret);
            ret2->pickle_size = read_arbitrary<uint32_t>(f, 4);
            ret2->tabid = read_arbitrary<int32_t>(f, 4);
            read_string(f, ret2->session_storage_persistent_id, false);
            break;
        }
        case 20: // CommandSetActiveWindow
        {
            ret = std::shared_ptr<CommandSetActiveWindow>(new CommandSetActiveWindow());
            std::shared_ptr<CommandSetActiveWindow> ret2 = std::static_pointer_cast<CommandSetActiveWindow>(ret);
            ret2->window_id = read_arbitrary<uint32_t>(f, 4);
            break;
        }
        case 21: // CommandLastActiveTime
        {
            ret = std::shared_ptr<CommandLastActiveTime>(new CommandLastActiveTime());
            std::shared_ptr<CommandLastActiveTime> ret2 = std::static_pointer_cast<CommandLastActiveTime>(ret);
            ret2->id = read_arbitrary<int32_t>(f, 4);
            ret2->UNKNOWN_0 = read_arbitrary<int32_t>(f, 4); // TODO
            ret2->last_active_time = read_arbitrary<int64_t>(f, 8);
            break;
        }
        case 23: // CommandSetWindowWorkspace2
        {
            ret = std::shared_ptr<CommandSetWindowWorkspace2>(new CommandSetWindowWorkspace2());
            std::shared_ptr<CommandSetWindowWorkspace2> ret2 = std::static_pointer_cast<CommandSetWindowWorkspace2>(ret);
            ret2->pickle_size = read_arbitrary<uint32_t>(f, 4);
            ret2->window_id = read_arbitrary<int32_t>(f, 4);
            read_string(f, ret2->workspace, false);
            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
    // Size already includes the 2 bytes from the uint16 size
    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, -0x68(%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 0x35ae
movq 0x6a4e(%rip), %rdi      # 0x9ff0
leaq 0x2ad4(%rip), %rsi      # 0x607d
callq 0x3110
movzbl %r15b, %r15d
movzwl %r12w, %eax
movq %rax, -0x60(%rbp)
cmpb $0x17, %r15b
ja 0x3a11
leaq 0x2a39(%rip), %rax      # 0x6004
movslq (%rax,%r15,4), %rcx
addq %rax, %rcx
jmpq *%rcx
pushq $0x18
popq %rdi
callq 0x3120
andq $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
leaq 0x61b2(%rip), %rcx      # 0x97a0
movq %rcx, (%rax)
leaq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x4cde
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x4da6
leaq -0x40(%rbp), %rdi
callq 0x4a10
leaq -0x48(%rbp), %rdi
movq %rbx, %rsi
callq 0x477e
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x46df
movq -0x48(%rbp), %rcx
movl %eax, 0x10(%rcx)
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x4760
leaq -0x40(%rbp), %rdi
movq -0x8(%rdi), %rcx
movl %eax, 0x14(%rcx)
jmp 0x3bf7
pushq $0x18
popq %rdi
callq 0x3120
andq $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
leaq 0x621b(%rip), %rcx      # 0x9880
movq %rcx, (%rax)
leaq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x50e6
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x51ae
leaq -0x40(%rbp), %rdi
callq 0x4a10
leaq -0x48(%rbp), %rdi
movq %rbx, %rsi
callq 0x4835
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x46df
leaq -0x40(%rbp), %rdi
movq -0x8(%rdi), %rcx
movl %eax, 0x10(%rcx)
jmp 0x3bf7
pushq $0x38
popq %rdi
callq 0x3120
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
andq $0x0, 0x30(%rax)
movaps %xmm0, 0x10(%rax)
movaps %xmm0, 0x20(%rax)
leaq 0x6176(%rip), %rcx      # 0x9848
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x28, %rcx
movq %rcx, 0x18(%rax)
movb $0x0, 0x28(%rax)
leaq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x4fe4
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x50ac
leaq -0x40(%rbp), %rdi
callq 0x4a10
leaq -0x48(%rbp), %rdi
movq %rbx, %rsi
callq 0x480f
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x46df
movq -0x48(%rbp), %rcx
movl %eax, 0x10(%rcx)
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x4760
movq -0x48(%rbp), %rsi
movl %eax, 0x14(%rsi)
addq $0x18, %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x339d
jmp 0x3af0
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 0x5fbc(%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 -0x58(%rbp), %rdi
movq %rbx, %rsi
callq 0x473a
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x46df
movq -0x58(%rbp), %rcx
movl %eax, 0x10(%rcx)
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x4760
movq -0x58(%rbp), %rcx
movl %eax, 0x14(%rcx)
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x4760
movq -0x58(%rbp), %rsi
movl %eax, 0x18(%rsi)
addq $0x20, %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x339d
testb %al, %al
je 0x3830
leaq -0x48(%rbp), %rdi
pushq $0x1
popq %rdx
movq %r14, %rsi
callq 0x3444
movq -0x58(%rbp), %rdi
addq $0x40, %rdi
leaq -0x48(%rbp), %r13
movq %r13, %rsi
callq 0x3210
movq %r13, %rdi
callq 0x3030
leaq -0x50(%rbp), %rdi
jmp 0x3bf7
pushq $0x20
popq %rdi
callq 0x3120
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movaps %xmm0, 0x10(%rax)
leaq 0x5fbe(%rip), %rcx      # 0x9810
movq %rcx, (%rax)
leaq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x4ee2
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x4faa
leaq -0x40(%rbp), %rdi
callq 0x4a10
leaq -0x48(%rbp), %rdi
movq %rbx, %rsi
callq 0x47ca
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
jmp 0x3beb
pushq $0x28
popq %rdi
callq 0x3120
xorps %xmm0, %xmm0
andq $0x0, 0x20(%rax)
movaps %xmm0, (%rax)
movaps %xmm0, 0x10(%rax)
leaq 0x5f04(%rip), %rcx      # 0x97d8
movq %rcx, (%rax)
leaq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x4de0
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x4ea8
leaq -0x40(%rbp), %rdi
callq 0x4a10
leaq -0x48(%rbp), %rdi
movq %rbx, %rsi
callq 0x47a4
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 $0x4
popq %rsi
movq %r14, %rdi
callq 0x4760
movq -0x48(%rbp), %rcx
movl %eax, 0x18(%rcx)
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x4760
movq -0x48(%rbp), %rcx
movl %eax, 0x1c(%rcx)
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x4760
movq -0x48(%rbp), %rcx
movl %eax, 0x20(%rcx)
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x4760
leaq -0x40(%rbp), %rdi
movq -0x8(%rdi), %rcx
movl %eax, 0x24(%rcx)
jmp 0x3bf7
pushq $0x38
popq %rdi
callq 0x3120
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
andq $0x0, 0x30(%rax)
movaps %xmm0, 0x10(%rax)
movaps %xmm0, 0x20(%rax)
leaq 0x5f55(%rip), %rcx      # 0x98f0
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x28, %rcx
movq %rcx, 0x18(%rax)
movb $0x0, 0x28(%rax)
leaq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x52ea
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x53b2
leaq -0x40(%rbp), %rdi
callq 0x4a10
leaq -0x48(%rbp), %rdi
movq %rbx, %rsi
callq 0x4881
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x46df
movq -0x48(%rbp), %rcx
movl %eax, 0x10(%rcx)
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x4760
movq -0x48(%rbp), %rsi
movl %eax, 0x14(%rsi)
addq $0x18, %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x339d
jmp 0x3af0
movq 0x65d8(%rip), %r13      # 0x9ff0
leaq 0x26a8(%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 0x2693(%rip), %rsi      # 0x60ec
movq %r13, %rdi
callq 0x3110
movq %rax, %rdi
movq -0x68(%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 0x2667(%rip), %rsi      # 0x60f0
movq %rax, %rdi
callq 0x3110
movq %rax, %rdi
movq -0x60(%rbp), %rsi
callq 0x31c0
leaq 0x25d4(%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 0x5cab(%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
jmp 0x3bf7
pushq $0x20
popq %rdi
callq 0x3120
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movaps %xmm0, 0x10(%rax)
leaq 0x5cfe(%rip), %rcx      # 0x9810
movq %rcx, (%rax)
leaq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x4ee2
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x4faa
leaq -0x40(%rbp), %rdi
callq 0x4a10
leaq -0x48(%rbp), %rdi
movq %rbx, %rsi
callq 0x47ca
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
jmp 0x3beb
pushq $0x20
popq %rdi
callq 0x3120
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movaps %xmm0, 0x10(%rax)
leaq 0x5d2c(%rip), %rcx      # 0x98b8
movq %rcx, (%rax)
leaq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x51e8
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x52b0
leaq -0x40(%rbp), %rdi
callq 0x4a10
leaq -0x48(%rbp), %rdi
movq %rbx, %rsi
callq 0x485b
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)
callq 0x4a10
movq (%rbx), %rax
movw %r12w, 0x8(%rax)
movl %r15d, 0xc(%rax)
movq %r14, %rdi
callq 0x31e0
movq -0x68(%rbp), %rcx
movq -0x60(%rbp), %rdx
addl %edx, %ecx
addl $0x2, %ecx
movslq %ecx, %rsi
cmpq %rsi, %rax
jge 0x3c2f
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 0x3c61
jmp 0x3c6c
jmp 0x3c82
jmp 0x3c82
jmp 0x3c82
jmp 0x3c82
jmp 0x3c82
jmp 0x3c82
jmp 0x3c82
jmp 0x3c82
jmp 0x3c82
jmp 0x3c6c
jmp 0x3c6c
jmp 0x3c6c
jmp 0x3c6c
jmp 0x3c6c
movq %rax, %r14
leaq -0x50(%rbp), %rdi
jmp 0x3c73
jmp 0x3c6c
movq %rax, %r14
leaq -0x40(%rbp), %rdi
callq 0x4a10
jmp 0x3c85
jmp 0x3c82
jmp 0x3c82
jmp 0x3c82
jmp 0x3c82
movq %rax, %r14
addq $0x8, %rbx
movq %rbx, %rdi
callq 0x4a10
movq %r14, %rdi
callq 0x31f0