// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
xorl %eax, %eax
movq %rax, -0x40(%rbp)
leaq -0x68(%rbp), %rdx
movaps %xmm0, -0x8(%rdx)
movaps %xmm0, 0x8(%rdx)
movaps %xmm0, -0x18(%rdx)
movaps %xmm0, -0x28(%rdx)
leaq 0x1bd7(%rip), %rcx      # 0xb620
movq %rcx, (%rdx)
movq $0x3, 0x8(%rdx)
movq %rax, 0x10(%rdx)
leaq 0x1d40(%rip), %rdx      # 0xb79f
movl %edi, -0x2c(%rbp)
movq %rsi, %r15
callq 0x22b0
movl %eax, %ebx
movq 0x6555(%rip), %r12      # 0xffc8
movq (%r12), %rdi
callq 0x9cb8
movq %rax, %r13
leaq 0x1b42(%rip), %r14      # 0xb5c8
movq %r13, (%r12)
leal -0x61(%rbx), %eax
cmpl $0x15, %eax
ja 0x9b1a
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq %r13, -0x70(%rbp)
jmp 0x9b28
movq %r13, %rdi
callq 0x22d0
cltq
movq %rax, -0x60(%rbp)
jmp 0x9b28
movq %r13, -0x88(%rbp)
jmp 0x9b28
movq %r13, -0x90(%rbp)
jmp 0x9b28
movq %r13, %rdi
movl $0x2e, %esi
callq 0x2130
testq %rax, %rax
je 0x9c6a
movb $0x0, (%rax)
movq (%r12), %rcx
movq %rcx, -0x80(%rbp)
incq %rax
movq %rax, -0x78(%rbp)
jmp 0x9b28
movq %r13, %rdi
callq 0x22d0
movl %eax, -0x48(%rbp)
jmp 0x9b28
movq %r13, -0x68(%rbp)
jmp 0x9b28
movb $0x1, -0x40(%rbp)
jmp 0x9b28
movq %r13, %rdi
callq 0x22d0
movl %eax, -0x44(%rbp)
jmp 0x9b28
cmpl $-0x1, %ebx
je 0x9b4d
cmpl $0x3f, %ebx
je 0x9c72
movl -0x2c(%rbp), %edi
movq %r15, %rsi
leaq 0x1c6a(%rip), %rdx      # 0xb79f
callq 0x22b0
movl %eax, %ebx
movq (%r12), %rdi
callq 0x9cb8
movq %rax, %r13
jmp 0x9a86
cmpq $0x0, -0x90(%rbp)
je 0x9c9a
cmpq $0x0, -0x88(%rbp)
je 0x9c9f
cmpq $0x0, -0x80(%rbp)
je 0x9ca4
cmpq $0x0, -0x78(%rbp)
je 0x9ca9
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x9cae
cmpq $0x0, -0x60(%rbp)
jle 0x9cb3
callq 0x4160
testq %rax, %rax
je 0x9c91
movq %rax, %rbx
movq %rax, %rdi
callq 0x591a
testl %eax, %eax
jne 0x9bc4
movq %rbx, %rdi
callq 0x5906
testl %eax, %eax
je 0x9c91
movq %rbx, %rdi
callq 0x3af0
movq -0x68(%rbp), %rdi
callq 0x4160
testq %rax, %rax
je 0x9c88
movq %rax, %rbx
movq %rax, %rdi
callq 0x591a
testl %eax, %eax
je 0x9c88
movq %rbx, %rdi
callq 0x3af0
cmpl $0x0, -0x44(%rbp)
jle 0x9c3e
cmpl $0x0, -0x48(%rbp)
jle 0x9c3e
movl $0x400, %edi            # imm = 0x400
callq 0x2d6c
leaq -0x50(%rbp), %rbx
movq %rax, (%rbx)
leaq -0x90(%rbp), %rdi
movq %rbx, %rsi
callq 0x8ffa
movq (%rbx), %rdi
testb %al, %al
je 0x9c51
callq 0x3715
movq -0x50(%rbp), %rdi
callq 0x2f4e
xorl %eax, %eax
jmp 0x9c5b
leaq -0x90(%rbp), %rdi
callq 0x9160
xorb $0x1, %al
movzbl %al, %eax
jmp 0x9c5b
callq 0x2f4e
movl $0x1, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x2aa9
leaq 0x1b39(%rip), %rdi      # 0xb7b2
callq 0x2070
movl $0x1, %edi
callq 0x2300
leaq -0x68(%rbp), %rdi
callq 0x2b10
leaq -0x70(%rbp), %rdi
callq 0x2b46
callq 0x2c4c
callq 0x2c18
callq 0x2be4
callq 0x2bb0
callq 0x2b7c
callq 0x2adc