// File: /workspace/github_cpp_makefile_star2_O1/yayuntian[P]user_agent/test_ua.cpp
// Function: main
int main(int argc, char **argv) {
    int opt;
    string str = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) "
        "AppleWebKit/537.36 (KHTML, like Gecko)"
        " Chrome/43.0.2357.130 Safari/537.36 JianKongBao Monitor 1.1";
    int perf = 0;
    int loop = 100000;

    while ((opt = getopt(argc, argv, "ptjc:h")) != -1) {
        switch (opt) {
            case 'p':
                perf = 1;
                break;
            case 't':
                TestUserAgent();
                exit(0);
            case 'c':
                loop = atoi(optarg);
                break;
            case 'h':
            default:
                goto usage;
        }
    }

    if (perf == 1) {
        if (argc - optind > 0) {
            str = argv[optind];
        }
        BenchmarkUserAgent(str, loop);
        exit(0);
    }

    if (argc - optind > 0) {
        str = argv[optind];
        UserAgent ua;
        Parse(ua, str, str.size());
        echo_ua(ua);
        exit(0);
    }

usage:
    printf("Usage: %s <option> [user_agent]\n", argv[0]);
    printf("General options:\n"
            " -t              Unit test\n"
            " -p              Perf test\n"
            " -c <count>      Perf test loop count\n"
            " -h              Show help\n"
          );
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %rsi, %r14
movl %edi, %ebp
leaq 0x10(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x25055(%rip), %rsi     # 0x333f1
leaq 0x250df(%rip), %rdx     # 0x33482
movq %rsp, %rdi
callq 0xe90a
movl $0x186a0, %ebx          # imm = 0x186A0
movb $0x1, %r12b
leaq 0x250c9(%rip), %r15     # 0x33483
movq 0x37bdf(%rip), %r13     # 0x45fa0
movl %ebp, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x70b0
cmpl $0x63, %eax
jne 0xe3e0
movq (%r13), %rdi
callq 0x7560
movl %eax, %ebx
jmp 0xe3c1
cmpl $-0x1, %eax
je 0xe400
cmpl $0x70, %eax
jne 0xe3ef
xorl %r12d, %r12d
jmp 0xe3c1
cmpl $0x74, %eax
jne 0xe418
callq 0xde31
xorl %edi, %edi
callq 0x7400
movq 0x37bc9(%rip), %rax     # 0x45fd0
movslq (%rax), %rax
testb $0x1, %r12b
je 0xe464
cmpl %ebp, %eax
jl 0xe4ae
movq (%r14), %rsi
leaq 0x25068(%rip), %rdi     # 0x3348a
xorl %eax, %eax
callq 0x7070
leaq 0x250d6(%rip), %rdi     # 0x33506
callq 0x7530
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xe450
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x7340
xorl %eax, %eax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl %ebp, %eax
jge 0xe474
movq (%r14,%rax,8), %rsi
movq %rsp, %rdi
callq 0x7490
leaq 0x50(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x40(%rsp), %rdi
callq 0xe87a
leaq 0x40(%rsp), %rdi
movl %ebx, %esi
callq 0xe1a7
leaq 0x40(%rsp), %rdi
callq 0x76e8
jmp 0xe3f9
movq (%r14,%rax,8), %rsi
movq %rsp, %rdi
callq 0x7490
leaq 0x70(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x90(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0xb0(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0xd0(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0xf0(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x110(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x130(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x150(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x170(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x30(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x20(%rsp), %rdi
callq 0xe87a
movl 0x8(%rsp), %edx
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0xefe0
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xe5a4
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x7340
leaq 0x60(%rsp), %rdi
callq 0xf1cb
jmp 0xe3f9
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xe5ee
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x7340
jmp 0xe5ee
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0xe5fd
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x7340
jmp 0xe5fd
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0xe772
jmp 0xe5fd
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xe618
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x7340
movq %rbx, %rdi
callq 0x7630