// File: /workspace/github_cpp_makefile_star2_O3/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 0x252d5(%rip), %rsi     # 0x313f1
leaq 0x2535f(%rip), %rdx     # 0x31482
movq %rsp, %rdi
callq 0xc690
movl $0x186a0, %ebx          # imm = 0x186A0
movb $0x1, %r12b
leaq 0x25349(%rip), %r15     # 0x31483
movq 0x37e5f(%rip), %r13     # 0x43fa0
movl %ebp, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x60b0
cmpl $0x63, %eax
jne 0xc160
movq (%r13), %rdi
callq 0x6560
movl %eax, %ebx
jmp 0xc141
cmpl $-0x1, %eax
je 0xc180
cmpl $0x70, %eax
jne 0xc16f
xorl %r12d, %r12d
jmp 0xc141
cmpl $0x74, %eax
jne 0xc198
callq 0xbbaa
xorl %edi, %edi
callq 0x6400
movq 0x37e49(%rip), %rax     # 0x43fd0
movslq (%rax), %rax
testb $0x1, %r12b
je 0xc1e4
cmpl %ebp, %eax
jl 0xc22e
movq (%r14), %rsi
leaq 0x252e8(%rip), %rdi     # 0x3148a
xorl %eax, %eax
callq 0x6070
leaq 0x25356(%rip), %rdi     # 0x31506
callq 0x6530
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xc1d0
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6340
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 0xc1f4
movq (%r14,%rax,8), %rsi
movq %rsp, %rdi
callq 0x6490
leaq 0x50(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x40(%rsp), %rdi
callq 0xc5fa
leaq 0x40(%rsp), %rdi
movl %ebx, %esi
callq 0xbf27
leaq 0x40(%rsp), %rdi
callq 0x66e8
jmp 0xc179
movq (%r14,%rax,8), %rsi
movq %rsp, %rdi
callq 0x6490
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 0xc5fa
movl 0x8(%rsp), %edx
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0xcd6e
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xc324
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6340
leaq 0x60(%rsp), %rdi
callq 0xcf59
jmp 0xc179
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xc36e
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6340
jmp 0xc36e
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0xc37d
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x6340
jmp 0xc37d
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0xc4f2
jmp 0xc37d
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xc398
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6340
movq %rbx, %rdi
callq 0x6630