// File: 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
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x88c0
movq -0x1c8(%rbp), %rdx
leaq 0x57372(%rip), %rsi     # 0x6a439
leaq -0x38(%rbp), %rdi
callq 0x13330
jmp 0x130d2
leaq -0x39(%rbp), %rdi
callq 0x8510
movl $0x0, -0x50(%rbp)
movl $0x186a0, -0x54(%rbp)   # imm = 0x186A0
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x573d4(%rip), %rdx     # 0x6a4cb
callq 0x80e0
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
je 0x13195
movl -0x14(%rbp), %eax
addl $-0x63, %eax
movl %eax, %ecx
movq %rcx, -0x1d0(%rbp)
subl $0x11, %eax
ja 0x1318b
movq -0x1d0(%rbp), %rax
leaq 0x52ee6(%rip), %rcx     # 0x66010
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x8510
jmp 0x13325
movl $0x1, -0x50(%rbp)
jmp 0x13190
callq 0x12c80
jmp 0x1315d
xorl %edi, %edi
callq 0x85a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1331c
movq 0x7ee24(%rip), %rax     # 0x91fa0
movq (%rax), %rdi
callq 0x8750
movl %eax, -0x54(%rbp)
jmp 0x13190
jmp 0x1318b
jmp 0x132d9
jmp 0x130e9
cmpl $0x1, -0x50(%rbp)
jne 0x13212
movl -0x8(%rbp), %eax
movq 0x7ee2b(%rip), %rcx     # 0x91fd0
subl (%rcx), %eax
cmpl $0x0, %eax
jle 0x131cb
movq -0x10(%rbp), %rax
movq 0x7ee19(%rip), %rcx     # 0x91fd0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rsi
leaq -0x38(%rbp), %rdi
callq 0x8670
jmp 0x131c9
jmp 0x131cb
leaq -0x78(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x81c0
jmp 0x131da
movl -0x54(%rbp), %esi
leaq -0x78(%rbp), %rdi
callq 0x12f00
jmp 0x131e8
leaq -0x78(%rbp), %rdi
callq 0x89e8
xorl %edi, %edi
callq 0x85a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x89e8
jmp 0x1331c
movl -0x8(%rbp), %eax
movq 0x7edb4(%rip), %rcx     # 0x91fd0
subl (%rcx), %eax
cmpl $0x0, %eax
jle 0x132d7
movq -0x10(%rbp), %rax
movq 0x7ed9e(%rip), %rcx     # 0x91fd0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rsi
leaq -0x38(%rbp), %rdi
callq 0x8670
jmp 0x13244
leaq -0x1a0(%rbp), %rdi
callq 0x136a0
leaq -0x1c0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x81c0
jmp 0x13262
leaq -0x38(%rbp), %rdi
callq 0x8350
movl %eax, %edx
leaq -0x1a0(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x14bd0
jmp 0x13282
leaq -0x1c0(%rbp), %rdi
callq 0x89e8
leaq -0x1a0(%rbp), %rdi
callq 0x14ee0
jmp 0x1329c
xorl %edi, %edi
callq 0x85a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x132c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x89e8
leaq -0x1a0(%rbp), %rdi
callq 0x138f0
jmp 0x1331c
jmp 0x132d9
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0x571eb(%rip), %rdi     # 0x6a4d2
xorl %eax, %eax
callq 0x8070
jmp 0x132f0
leaq 0x571fc(%rip), %rdi     # 0x6a4f3
xorl %eax, %eax
callq 0x8070
jmp 0x13300
movl $0x0, -0x4(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x89e8
movl -0x4(%rbp), %eax
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x89e8
movq -0x48(%rbp), %rdi
callq 0x88a0
nop