// File: /workspace/github_c_makefile_star2_O2/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
andq $0x0, -0x80(%rbp)
movaps %xmm0, -0x90(%rbp)
andq $0x0, -0xb0(%rbp)
movaps %xmm0, -0xc0(%rbp)
movaps %xmm0, -0xd0(%rbp)
leaq 0x1cd8(%rip), %rax      # 0xa770
movq %rax, -0x38(%rbp)
movq %rax, -0xa8(%rbp)
movq $0x3, -0xa0(%rbp)
andq $0x0, -0x98(%rbp)
leaq 0x1e32(%rip), %rdx      # 0xa8ef
movl %edi, -0x3c(%rbp)
movq %rsi, %rbx
callq 0x22b0
movl %eax, %r12d
movq 0x64f6(%rip), %r14      # 0xefc8
movq (%r14), %rdi
callq 0x8e29
movq %rax, %r15
pushq $0x3
popq %rax
movq %rax, -0x60(%rbp)
movq $0x0, -0x58(%rbp)
leaq 0x1c25(%rip), %r13      # 0xa718
movl $0x0, -0x2c(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x68(%rbp)
movq %r15, (%r14)
leal -0x61(%r12), %eax
cmpl $0x15, %eax
ja 0x8bf3
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movq %r15, -0xb0(%rbp)
movq %r15, -0x78(%rbp)
jmp 0x8c03
movq %r15, %rdi
callq 0x22d0
cltq
movq %rax, -0x60(%rbp)
movq %rax, -0xa0(%rbp)
jmp 0x8c03
movq %r15, -0xc8(%rbp)
movq %r15, -0x70(%rbp)
jmp 0x8c03
movq %r15, -0xd0(%rbp)
movq %r15, -0x68(%rbp)
jmp 0x8c03
movq %r15, %rdi
pushq $0x2e
popq %rsi
callq 0x2130
testq %rax, %rax
je 0x8d54
movb $0x0, (%rax)
movq (%r14), %rdx
movq %rdx, -0x48(%rbp)
movq %rdx, -0xc0(%rbp)
incq %rax
movq %rax, -0x50(%rbp)
movq %rax, -0xb8(%rbp)
jmp 0x8c03
movq %r15, %rdi
callq 0x22d0
movq %rax, -0x58(%rbp)
movl %eax, -0x88(%rbp)
jmp 0x8c03
movq %r15, -0xa8(%rbp)
movq %r15, -0x38(%rbp)
jmp 0x8c03
movb $0x1, -0x80(%rbp)
jmp 0x8c03
movq %r15, %rdi
callq 0x22d0
movl %eax, -0x2c(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x8c03
cmpl $-0x1, %r12d
je 0x8c28
cmpl $0x3f, %r12d
je 0x8d6f
movl -0x3c(%rbp), %edi
movq %rbx, %rsi
leaq 0x1cdf(%rip), %rdx      # 0xa8ef
callq 0x22b0
movl %eax, %r12d
movq (%r14), %rdi
callq 0x8e29
movq %rax, %r15
jmp 0x8b22
cmpq $0x0, -0x68(%rbp)
je 0x8da1
cmpq $0x0, -0x70(%rbp)
movq -0x50(%rbp), %rax
je 0x8db4
cmpq $0x0, -0x48(%rbp)
movq -0x78(%rbp), %r14
je 0x8dc9
testq %rax, %rax
je 0x8dde
testq %r14, %r14
je 0x8df3
cmpq $0x0, -0x60(%rbp)
jle 0x8e08
movq %r14, %rdi
callq 0x372f
testq %rax, %rax
je 0x8d8b
movq %rax, %rbx
movq %rax, %rdi
callq 0x499b
testl %eax, %eax
jne 0x8c9e
movq %rbx, %rdi
callq 0x4987
testl %eax, %eax
je 0x8d8b
movq %rbx, %rdi
callq 0x3060
movq -0x38(%rbp), %rdi
callq 0x372f
testq %rax, %rax
je 0x8d74
movq %rax, %rbx
movq %rax, %rdi
callq 0x499b
testl %eax, %eax
je 0x8d74
movq %rbx, %rdi
callq 0x3060
cmpl $0x0, -0x2c(%rbp)
setg %al
cmpl $0x0, -0x58(%rbp)
setg %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x8d27
movl $0x400, %edi            # imm = 0x400
callq 0x24ac
leaq -0x90(%rbp), %rbx
movq %rax, (%rbx)
leaq -0xd0(%rbp), %rdi
movq %rbx, %rsi
callq 0x7f42
movq (%rbx), %rdi
testb %al, %al
je 0x8d3a
callq 0x2d73
movq -0x90(%rbp), %rdi
callq 0x2669
xorl %eax, %eax
jmp 0x8d42
leaq -0xd0(%rbp), %rdi
callq 0x80bd
xorb $0x1, %al
movzbl %al, %eax
jmp 0x8d42
callq 0x2669
pushq $0x1
popq %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x629d(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x1a0e(%rip), %rsi      # 0xa773
movq %r15, %rdx
xorl %eax, %eax
callq 0x21e0
callq 0x8e99
movq 0x627d(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x1b3d(%rip), %rsi      # 0xa8c2
movq -0x38(%rbp), %rdx
jmp 0x8d68
movq 0x6266(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x1af7(%rip), %rsi      # 0xa893
movq %r14, %rdx
jmp 0x8d68
movq 0x6250(%rip), %rax      # 0xeff8
movq (%rax), %rcx
leaq 0x19df(%rip), %rdi      # 0xa791
jmp 0x8dc5
movq 0x623d(%rip), %rax      # 0xeff8
movq (%rax), %rcx
leaq 0x19f0(%rip), %rdi      # 0xa7b5
pushq $0x23
jmp 0x8e1b
movq 0x6228(%rip), %rax      # 0xeff8
movq (%rax), %rcx
leaq 0x19ff(%rip), %rdi      # 0xa7d9
pushq $0x33
jmp 0x8e1b
movq 0x6213(%rip), %rax      # 0xeff8
movq (%rax), %rcx
leaq 0x1a1e(%rip), %rdi      # 0xa80d
pushq $0x32
jmp 0x8e1b
movq 0x61fe(%rip), %rax      # 0xeff8
movq (%rax), %rcx
leaq 0x1a3c(%rip), %rdi      # 0xa840
pushq $0x2d
jmp 0x8e1b
movq 0x61e9(%rip), %rax      # 0xeff8
movq (%rax), %rcx
leaq 0x1a55(%rip), %rdi      # 0xa86e
pushq $0x24
popq %rsi
pushq $0x1
popq %rdx
callq 0x2320
callq 0x8e99