// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
movl %edi, %r14d
leaq 0x2100e(%rip), %rsi     # 0x2b3f1
movq %rsp, %rdi
leaq 0x60(%rsp), %rdx
callq 0xa55c
movl $0x186a0, %ebp          # imm = 0x186A0
movb $0x1, %r13b
leaq 0x21084(%rip), %r15     # 0x2b483
movq 0x36baa(%rip), %r12     # 0x40fb0
movl %r14d, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x70a0
cmpl $0x63, %eax
jne 0xa426
movq (%r12), %rdi
callq 0x7550
movl %eax, %ebp
jmp 0xa406
cmpl $-0x1, %eax
je 0xa446
cmpl $0x70, %eax
jne 0xa435
xorl %r13d, %r13d
jmp 0xa406
cmpl $0x74, %eax
jne 0xa45b
callq 0xa137
xorl %edi, %edi
callq 0x73f0
movq 0x36b8b(%rip), %rax     # 0x40fd8
movslq (%rax), %rax
testb $0x1, %r13b
je 0xa494
cmpl %r14d, %eax
jl 0xa4cd
movq (%rbx), %rsi
leaq 0x21025(%rip), %rdi     # 0x2b48a
xorl %eax, %eax
callq 0x7060
leaq 0x21093(%rip), %rdi     # 0x2b506
callq 0x7530
movq %rsp, %rdi
callq 0x7748
xorl %eax, %eax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl %r14d, %eax
jge 0xa4a5
movq (%rbx,%rax,8), %rsi
movq %rsp, %rdi
callq 0x7700
leaq 0x40(%rsp), %rdi
movq %rsp, %rsi
callq 0x7490
leaq 0x40(%rsp), %rdi
movl %ebp, %esi
callq 0xa2b6
leaq 0x40(%rsp), %rdi
callq 0x7748
jmp 0xa43f
movq (%rbx,%rax,8), %rsi
movq %rsp, %rdi
callq 0x7700
leaq 0x60(%rsp), %rdi
callq 0xa6a8
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x7490
movl 0x8(%rsp), %edx
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0xad79
leaq 0x20(%rsp), %rdi
callq 0x7748
leaq 0x60(%rsp), %rdi
callq 0xaf21
jmp 0xa43f
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x7748
jmp 0xa53d
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x7748
jmp 0xa54c
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0xa772
jmp 0xa54c
movq %rax, %rbx
movq %rsp, %rdi
callq 0x7748
movq %rbx, %rdi
callq 0x7640