// File: /workspace/github_c_makefile_star2_O3/goghcrow[P]dubbo_ab/dubbo.c
// Function: main
int main(int argc, char **argv)
{
    struct dubbo_async_args async_args;
    memset(&async_args, 0, sizeof(async_args));
    async_args.req_n = 0;
    async_args.pipe_n = 0;
    async_args.verbos = false;

    struct dubbo_args args;
    memset(&args, 0, sizeof(args));
    args.attach = "{}";
    args.timeout.tv_sec = 3;
    args.timeout.tv_usec = 0;

    int opt = 0;
    opt = getopt(argc, argv, optString);
    optarg = trim_opt(optarg);
    while (opt != -1)
    {
        switch (opt)
        {
        case 'h':
            args.host = optarg;
            break;
        case 'p':
            args.port = optarg;
            break;
        case 'm':
        {
            char *c = strrchr(optarg, '.');
            ASSERT_OPT(c, "Invalid method %s", optarg);
            *c = 0;
            args.service = optarg;
            args.method = c + 1;
        }
        break;
        case 'a':
            args.args = optarg;
            break;
        case 'e':
            args.attach = optarg;
            break;
        case 't':
            args.timeout.tv_sec = atoi(optarg);
            break;
        case 'c':
            async_args.pipe_n = atoi(optarg);
            break;
        case 'n':
            async_args.req_n = atoi(optarg);
            break;
        case 'v':
            async_args.verbos = true;
            break;
        case '?':
            usage();
            break;
        default:
            break;
        }
        opt = getopt(argc, argv, optString);
        optarg = trim_opt(optarg);
    }

    ASSERT_OPT(args.host, "Missing Host -h=${host}");
    ASSERT_OPT(args.port, "Missing Port -p=${port}");
    ASSERT_OPT(args.service, "Missing Service -m=${service}.${method}");
    ASSERT_OPT(args.method, "Missing Method -m=${service}.${method}");
    ASSERT_OPT(args.args, "Missing Arguments -a'${jsonargs}'");
    ASSERT_OPT(args.timeout.tv_sec > 0, "Timeout must be positive");

    cJSON *json_args = cJSON_Parse(args.args);
    ASSERT_OPT(json_args && (cJSON_IsObject(json_args) || cJSON_IsArray(json_args)), "Invalid Arguments JSON Format : %s", args.args);
    cJSON_Delete(json_args);

    cJSON *json_attach = cJSON_Parse(args.attach);
    ASSERT_OPT(json_attach && cJSON_IsObject(json_attach), "Invalid Attach JSON Format as %s", args.attach);
    cJSON_Delete(json_attach);

    // fprintf(stderr, "Invoking dubbo://%s:%s/%s.%s?args=%s&attach=%s\n", args.host, args.port, args.service, args.method, args.args, args.attach);

    if (async_args.req_n > 0 && async_args.pipe_n > 0)
    {
        async_args.el = aeCreateEventLoop(1024);
        if (dubbo_bench_async(&args, &async_args))
        {
            aeMain(async_args.el);
            aeDeleteEventLoop(async_args.el);
            return 0;
        }
        else
        {
            aeDeleteEventLoop(async_args.el);
            return 1;
        }
    }
    else
    {
        return dubbo_invoke_sync(&args) ? 0 : 1;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, -0x90(%rbp)
xorl %eax, %eax
movq %rax, -0x80(%rbp)
movq %rax, -0xb0(%rbp)
movaps %xmm0, -0xc0(%rbp)
movaps %xmm0, -0xd0(%rbp)
leaq 0x1d54(%rip), %rcx      # 0xb620
movq %rcx, -0x38(%rbp)
movq %rcx, -0xa8(%rbp)
movq $0x3, -0xa0(%rbp)
movq $0x0, -0x50(%rbp)
movq %rax, -0x98(%rbp)
leaq 0x1ea7(%rip), %rdx      # 0xb79f
movl %edi, %r13d
movq %rsi, %r14
callq 0x22b0
movl %eax, %r12d
movq 0x66bb(%rip), %rbx      # 0xffc8
movq (%rbx), %rdi
callq 0x9bdc
movq %rax, %r15
movl $0x3, %eax
movq %rax, -0x58(%rbp)
movl $0x0, -0x2c(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x60(%rbp)
movq %r15, (%rbx)
leal -0x61(%r12), %eax
cmpl $0x15, %eax
ja 0x9a2c
leaq 0x1c60(%rip), %rcx      # 0xb5c8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r15, -0xb0(%rbp)
movq %r15, -0x70(%rbp)
jmp 0x9a3c
movq %r15, %rdi
callq 0x22d0
cltq
movq %rax, -0x58(%rbp)
movq %rax, -0xa0(%rbp)
jmp 0x9a3c
movq %r15, -0xc8(%rbp)
movq %r15, -0x68(%rbp)
jmp 0x9a3c
movq %r15, -0xd0(%rbp)
movq %r15, -0x60(%rbp)
jmp 0x9a3c
movq %r15, %rdi
movl $0x2e, %esi
callq 0x2130
testq %rax, %rax
je 0x9b8f
movb $0x0, (%rax)
movq (%rbx), %rdx
movq %rdx, -0x40(%rbp)
movq %rdx, -0xc0(%rbp)
incq %rax
movq %rax, -0x48(%rbp)
movq %rax, -0xb8(%rbp)
jmp 0x9a3c
movq %r15, %rdi
callq 0x22d0
movq %rax, -0x50(%rbp)
movl %eax, -0x88(%rbp)
jmp 0x9a3c
movq %r15, -0xa8(%rbp)
movq %r15, -0x38(%rbp)
jmp 0x9a3c
movb $0x1, -0x80(%rbp)
jmp 0x9a3c
movq %r15, %rdi
callq 0x22d0
movl %eax, -0x2c(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x9a3c
cmpl $-0x1, %r12d
je 0x9a61
cmpl $0x3f, %r12d
je 0x9b97
movl %r13d, %edi
movq %r14, %rsi
leaq 0x1d56(%rip), %rdx      # 0xb79f
callq 0x22b0
movl %eax, %r12d
movq (%rbx), %rdi
callq 0x9bdc
movq %rax, %r15
jmp 0x9950
cmpq $0x0, -0x60(%rbp)
je 0x9bbe
cmpq $0x0, -0x68(%rbp)
movq -0x48(%rbp), %rax
je 0x9bc3
cmpq $0x0, -0x40(%rbp)
movq -0x70(%rbp), %r14
je 0x9bc8
testq %rax, %rax
je 0x9bcd
testq %r14, %r14
je 0x9bd2
cmpq $0x0, -0x58(%rbp)
jle 0x9bd7
movq %r14, %rdi
callq 0x40c3
testq %rax, %rax
je 0x9bb6
movq %rax, %rbx
movq %rax, %rdi
callq 0x585b
testl %eax, %eax
jne 0x9ad7
movq %rbx, %rdi
callq 0x5847
testl %eax, %eax
je 0x9bb6
movq %rbx, %rdi
callq 0x3a9a
movq -0x38(%rbp), %rdi
callq 0x40c3
testq %rax, %rax
je 0x9bad
movq %rax, %rbx
movq %rax, %rdi
callq 0x585b
testl %eax, %eax
je 0x9bad
movq %rbx, %rdi
callq 0x3a9a
cmpl $0x0, -0x2c(%rbp)
setg %al
cmpl $0x0, -0x50(%rbp)
setg %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x9b60
movl $0x400, %edi            # imm = 0x400
callq 0x2d4c
leaq -0x90(%rbp), %rbx
movq %rax, (%rbx)
leaq -0xd0(%rbp), %rdi
movq %rbx, %rsi
callq 0x8ec2
movq (%rbx), %rdi
testb %al, %al
je 0x9b73
callq 0x36ea
movq -0x90(%rbp), %rdi
callq 0x2f43
xorl %eax, %eax
jmp 0x9b7d
leaq -0xd0(%rbp), %rdi
callq 0x901c
xorb $0x1, %al
movzbl %al, %eax
jmp 0x9b7d
callq 0x2f43
movl $0x1, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x2a8d
leaq 0x1c14(%rip), %rdi      # 0xb7b2
callq 0x2070
movl $0x1, %edi
callq 0x2300
movq -0x38(%rbp), %rdi
callq 0x2af4
movq %r14, %rdi
callq 0x2b27
callq 0x2c2a
callq 0x2bf6
callq 0x2bc2
callq 0x2b8e
callq 0x2b5a
callq 0x2ac0