// File: instance01[P]chromium-snss-parse/examples/parse_print_types.cpp
// Function: main
int main(int argc, char* argv[]) {
    if (argc != 2) {
        std::cout << "Usage: " << argv[0] << " <filename>" << std::endl;
        std::cout << "For example on ArchLinux you could try and parse ";
        std::cout << "~/.config/chromium/Default/Current Session" << std::endl;
    }

    std::ifstream f(argv[1], std::ios::binary | std::ios::in);
    if (!f.is_open() || f.fail())
        return 1;

    std::vector<std::shared_ptr<Command>> cmds = read_session_file(f);

    for (auto & x : cmds) {
        std::cout << " Size: " << x->size << " Type: " << static_cast<uint16_t>(x->type) << std::endl;
    }

    f.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2a0, %rsp            # imm = 0x2A0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
je 0x5814
movq 0xc82a(%rip), %rdi      # 0x11fd0
leaq 0x598c(%rip), %rsi      # 0xb139
callq 0x3130
movq %rax, %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x3130
movq %rax, %rdi
leaq 0x5976(%rip), %rsi      # 0xb141
callq 0x3130
movq %rax, %rdi
movq 0xc7de(%rip), %rsi      # 0x11fb8
callq 0x3160
movq 0xc7ea(%rip), %rdi      # 0x11fd0
leaq 0x5960(%rip), %rsi      # 0xb14d
callq 0x3130
movq 0xc7d7(%rip), %rdi      # 0x11fd0
leaq 0x597f(%rip), %rsi      # 0xb17f
callq 0x3130
movq %rax, %rdi
movq 0xc7a9(%rip), %rsi      # 0x11fb8
callq 0x3160
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x278(%rbp)
movl $0x4, %edi
movl $0x8, %esi
callq 0x6b70
movq -0x278(%rbp), %rsi
movl %eax, %edx
leaq -0x218(%rbp), %rdi
movq %rdi, -0x270(%rbp)
callq 0x3260
movq -0x270(%rbp), %rdi
callq 0x31e0
movb %al, -0x261(%rbp)
jmp 0x5862
movb -0x261(%rbp), %al
testb $0x1, %al
jne 0x586e
jmp 0x589a
movq -0x218(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x218(%rbp,%rax), %rdi
callq 0x3030
movb %al, -0x279(%rbp)
jmp 0x588e
movb -0x279(%rbp), %al
testb $0x1, %al
jne 0x589a
jmp 0x58c7
movl $0x1, -0x4(%rbp)
movl $0x1, -0x228(%rbp)
jmp 0x5a2d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x5a45
leaq -0x240(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x5060
jmp 0x58dc
leaq -0x240(%rbp), %rax
movq %rax, -0x248(%rbp)
movq -0x248(%rbp), %rdi
callq 0x6bc0
movq %rax, -0x250(%rbp)
movq -0x248(%rbp), %rdi
callq 0x6bf0
movq %rax, -0x258(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x6c20
testb $0x1, %al
jne 0x592c
jmp 0x5a09
leaq -0x250(%rbp), %rdi
callq 0x6c60
movq %rax, -0x260(%rbp)
movq 0xc68a(%rip), %rdi      # 0x11fd0
leaq 0x585d(%rip), %rsi      # 0xb1aa
callq 0x3130
movq %rax, -0x288(%rbp)
jmp 0x595b
movq -0x260(%rbp), %rdi
callq 0x66a0
movq -0x288(%rbp), %rdi
movzwl 0x8(%rax), %esi
callq 0x3220
movq %rax, -0x290(%rbp)
jmp 0x5980
movq -0x290(%rbp), %rdi
leaq 0x5824(%rip), %rsi      # 0xb1b2
callq 0x3130
movq %rax, -0x298(%rbp)
jmp 0x599c
movq -0x260(%rbp), %rdi
callq 0x66a0
movq -0x298(%rbp), %rdi
movzwl 0xc(%rax), %esi
callq 0x3220
movq %rax, -0x2a0(%rbp)
jmp 0x59c1
movq -0x2a0(%rbp), %rdi
movq 0xc5e9(%rip), %rsi      # 0x11fb8
callq 0x3160
jmp 0x59d6
jmp 0x59d8
leaq -0x250(%rbp), %rdi
callq 0x6c80
jmp 0x5910
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x6b10
jmp 0x5a45
leaq -0x218(%rbp), %rdi
callq 0x3040
jmp 0x5a17
leaq -0x240(%rbp), %rdi
callq 0x6b10
movl $0x0, -0x228(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x3050
movl -0x4(%rbp), %eax
addq $0x2a0, %rsp            # imm = 0x2A0
popq %rbp
retq
leaq -0x218(%rbp), %rdi
callq 0x3050
movq -0x220(%rbp), %rdi
callq 0x3250
nopl (%rax)