// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/redis-benchmark.c
// Function: main
int main(int argc, const char **argv) {
    int i;
    char *data, *cmd;
    int len;

    client c;

    srandom(time(NULL));
    signal(SIGHUP, SIG_IGN);
    signal(SIGPIPE, SIG_IGN);

    config.numclients = 50;
    config.requests = 100000;
    config.liveclients = 0;
    config.el = aeCreateEventLoop(1024*10);
    aeCreateTimeEvent(config.el,1,showThroughput,NULL,NULL);
    config.keepalive = 1;
    config.datasize = 3;
    config.pipeline = 1;
    config.showerrors = 0;
    config.randomkeys = 0;
    config.randomkeys_keyspacelen = 0;
    config.quiet = 0;
    config.csv = 0;
    config.loop = 0;
    config.idlemode = 0;
    config.latency = NULL;
    config.clients = listCreate();
    config.hostip = "127.0.0.1";
    config.hostport = 6379;
    config.hostsocket = NULL;
    config.tests = NULL;
    config.dbnum = 0;
    config.auth = NULL;

    i = parseOptions(argc,argv);
    argc -= i;
    argv += i;

    config.latency = zmalloc(sizeof(long long)*config.requests);

    if (config.keepalive == 0) {
        printf("WARNING: keepalive disabled, you probably need 'echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse' for Linux and 'sudo sysctl -w net.inet.tcp.msl=1000' for Mac OS X in order to use a lot of clients/requests\n");
    }

    if (config.idlemode) {
        printf("Creating %d idle connections and waiting forever (Ctrl+C when done)\n", config.numclients);
        c = createClient("",0,NULL); /* will never receive a reply */
        createMissingClients(c);
        aeMain(config.el);
        /* and will wait for every */
    }

    /* Run benchmark with command in the remainder of the arguments. */
    if (argc) {
        sds title = sdsnew(argv[0]);
        for (i = 1; i < argc; i++) {
            title = sdscatlen(title, " ", 1);
            title = sdscatlen(title, (char*)argv[i], strlen(argv[i]));
        }

        do {
            len = redisFormatCommandArgv(&cmd,argc,argv,NULL);
            benchmark(title,cmd,len);
            free(cmd);
        } while(config.loop);

        return 0;
    }

    /* Run default benchmark suite. */
    data = zmalloc(config.datasize+1);
    do {
        memset(data,'x',config.datasize);
        data[config.datasize] = '\0';

        if (test_is_selected("ping_inline") || test_is_selected("ping"))
            benchmark("PING_INLINE","PING\r\n",6);

        if (test_is_selected("ping_mbulk") || test_is_selected("ping")) {
            len = redisFormatCommand(&cmd,"PING");
            benchmark("PING_BULK",cmd,len);
            free(cmd);
        }

        if (test_is_selected("set")) {
            len = redisFormatCommand(&cmd,"SET key:__rand_int__ %s",data);
            benchmark("SET",cmd,len);
            free(cmd);
        }

        if (test_is_selected("get")) {
            len = redisFormatCommand(&cmd,"GET key:__rand_int__");
            benchmark("GET",cmd,len);
            free(cmd);
        }

        if (test_is_selected("incr")) {
            len = redisFormatCommand(&cmd,"INCR counter:__rand_int__");
            benchmark("INCR",cmd,len);
            free(cmd);
        }

        if (test_is_selected("lpush")) {
            len = redisFormatCommand(&cmd,"LPUSH mylist %s",data);
            benchmark("LPUSH",cmd,len);
            free(cmd);
        }

        if (test_is_selected("rpush")) {
            len = redisFormatCommand(&cmd,"RPUSH mylist %s",data);
            benchmark("RPUSH",cmd,len);
            free(cmd);
        }

        if (test_is_selected("lpop")) {
            len = redisFormatCommand(&cmd,"LPOP mylist");
            benchmark("LPOP",cmd,len);
            free(cmd);
        }

        if (test_is_selected("rpop")) {
            len = redisFormatCommand(&cmd,"RPOP mylist");
            benchmark("RPOP",cmd,len);
            free(cmd);
        }

        if (test_is_selected("sadd")) {
            len = redisFormatCommand(&cmd,
                "SADD myset element:__rand_int__");
            benchmark("SADD",cmd,len);
            free(cmd);
        }

        if (test_is_selected("spop")) {
            len = redisFormatCommand(&cmd,"SPOP myset");
            benchmark("SPOP",cmd,len);
            free(cmd);
        }

        if (test_is_selected("lrange") ||
            test_is_selected("lrange_100") ||
            test_is_selected("lrange_300") ||
            test_is_selected("lrange_500") ||
            test_is_selected("lrange_600"))
        {
            len = redisFormatCommand(&cmd,"LPUSH mylist %s",data);
            benchmark("LPUSH (needed to benchmark LRANGE)",cmd,len);
            free(cmd);
        }

        if (test_is_selected("lrange") || test_is_selected("lrange_100")) {
            len = redisFormatCommand(&cmd,"LRANGE mylist 0 99");
            benchmark("LRANGE_100 (first 100 elements)",cmd,len);
            free(cmd);
        }

        if (test_is_selected("lrange") || test_is_selected("lrange_300")) {
            len = redisFormatCommand(&cmd,"LRANGE mylist 0 299");
            benchmark("LRANGE_300 (first 300 elements)",cmd,len);
            free(cmd);
        }

        if (test_is_selected("lrange") || test_is_selected("lrange_500")) {
            len = redisFormatCommand(&cmd,"LRANGE mylist 0 449");
            benchmark("LRANGE_500 (first 450 elements)",cmd,len);
            free(cmd);
        }

        if (test_is_selected("lrange") || test_is_selected("lrange_600")) {
            len = redisFormatCommand(&cmd,"LRANGE mylist 0 599");
            benchmark("LRANGE_600 (first 600 elements)",cmd,len);
            free(cmd);
        }

        if (test_is_selected("mset")) {
            const char *argv[21];
            argv[0] = "MSET";
            for (i = 1; i < 21; i += 2) {
                argv[i] = "key:__rand_int__";
                argv[i+1] = data;
            }
            len = redisFormatCommandArgv(&cmd,21,argv,NULL);
            benchmark("MSET (10 keys)",cmd,len);
            free(cmd);
        }

        if (!config.csv) printf("\n");
    } while(config.loop);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %r14
movl %edi, %ebx
xorl %r15d, %r15d
xorl %edi, %edi
callq 0xb350
movl %eax, %edi
callq 0xb090
movl $0x1, %esi
movl $0x1, %edi
callq 0xb2f0
movl $0x1, %esi
movl $0xd, %edi
callq 0xb2f0
movq $0x32, 0x37d74(%rip) # 0x4c458
movl $0x186a0, 0x37d72(%rip) # imm = 0x186A0
movl $0x2800, %edi           # imm = 0x2800
callq 0x1274c
movq %rax, 0x37d39(%rip)     # 0x4c438
leaq -0x1cd(%rip), %rdx      # 0x14539
movl $0x1, %esi
movq %rax, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x12b0a
movl $0x1, 0x37d5a(%rip)     # 0x4c47c
movl $0x3, 0x37d44(%rip)     # 0x4c470
movq $0x1, 0x37d49(%rip) # 0x4c480
movq %r15, 0x37d36(%rip)     # 0x4c474
movq %r15, 0x37d53(%rip)     # 0x4c498
xorps %xmm0, %xmm0
movups %xmm0, 0x37d61(%rip)    # 0x4c4b0
callq 0x15958
movq %rax, 0x37d4d(%rip)     # 0x4c4a8
leaq 0x24b89(%rip), %rax     # 0x392eb
movq %rax, 0x37cd7(%rip)     # 0x4c440
movl $0x18eb, 0x37cd5(%rip)  # imm = 0x18EB
movq %r15, 0x37cd6(%rip)     # 0x4c450
movl $0x0, 0x37d3c(%rip)     # 0x4c4c0
xorps %xmm0, %xmm0
movups %xmm0, 0x37d42(%rip)    # 0x4c4d0
movl %ebx, %edi
movq %r14, %rsi
callq 0x140f8
movl %eax, %ebp
movslq 0x37cbf(%rip), %rdi     # 0x4c460
shlq $0x3, %rdi
callq 0x15d39
movq %rax, 0x37ce7(%rip)     # 0x4c498
cmpl $0x0, 0x37cc4(%rip)     # 0x4c47c
jne 0x147c6
leaq 0x2590c(%rip), %rdi     # 0x3a0cd
callq 0xb0d0
cmpl $0x0, 0x37cef(%rip)     # 0x4c4bc
je 0x14807
movl 0x37c83(%rip), %esi     # 0x4c458
leaq 0x24b19(%rip), %rdi     # 0x392f5
xorl %eax, %eax
callq 0xb1c0
leaq 0x24f5b(%rip), %rdi     # 0x39745
xorl %esi, %esi
xorl %edx, %edx
callq 0x14de5
movq %rax, %rdi
callq 0x15154
movq 0x37c36(%rip), %rdi     # 0x4c438
callq 0x13098
cmpl %ebp, %ebx
jne 0x14d3e
movslq 0x37c5a(%rip), %rdi     # 0x4c470
incq %rdi
callq 0x15d39
movq %rax, %rbx
leaq 0x24c4c(%rip), %r12     # 0x39474
leaq 0x24b69(%rip), %r14     # 0x39398
leaq 0x8(%rsp), %rbp
leaq 0x24b9c(%rip), %r15     # 0x393d7
movslq 0x37c2e(%rip), %r13     # 0x4c470
movq %rbx, %rdi
movl $0x78, %esi
movq %r13, %rdx
callq 0xb230
movb $0x0, (%rbx,%r13)
leaq 0x24adc(%rip), %rdi     # 0x3933a
callq 0x14600
testl %eax, %eax
jne 0x14877
leaq 0x24ad8(%rip), %rdi     # 0x39346
callq 0x14600
testl %eax, %eax
je 0x1488f
leaq 0x24acd(%rip), %rdi     # 0x3934b
leaq 0x24ad2(%rip), %rsi     # 0x39357
movl $0x6, %edx
callq 0x151a6
leaq 0x24ac8(%rip), %rdi     # 0x3935e
callq 0x14600
testl %eax, %eax
jne 0x148af
leaq 0x24aa0(%rip), %rdi     # 0x39346
callq 0x14600
testl %eax, %eax
je 0x148dd
movq %rbp, %rdi
leaq 0x24ab0(%rip), %rsi     # 0x39369
xorl %eax, %eax
callq 0x17203
movq 0x8(%rsp), %rsi
leaq 0x24aa2(%rip), %rdi     # 0x3936e
movl %eax, %edx
callq 0x151a6
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x281fb(%rip), %rdi     # 0x3cadf
callq 0x14600
testl %eax, %eax
je 0x1491e
movq %rbp, %rdi
leaq 0x24a81(%rip), %rsi     # 0x39378
movq %rbx, %rdx
xorl %eax, %eax
callq 0x17203
movq 0x8(%rsp), %rsi
leaq 0x24c92(%rip), %rdi     # 0x3959f
movl %eax, %edx
callq 0x151a6
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x24a6b(%rip), %rdi     # 0x39390
callq 0x14600
testl %eax, %eax
je 0x1495c
movq %rbp, %rdi
leaq 0x24a5c(%rip), %rsi     # 0x39394
xorl %eax, %eax
callq 0x17203
movq 0x8(%rsp), %rsi
leaq 0x24a5e(%rip), %rdi     # 0x393a9
movl %eax, %edx
callq 0x151a6
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x24a4a(%rip), %rdi     # 0x393ad
callq 0x14600
testl %eax, %eax
je 0x1499a
movq %rbp, %rdi
leaq 0x24a3c(%rip), %rsi     # 0x393b2
xorl %eax, %eax
callq 0x17203
movq 0x8(%rsp), %rsi
leaq 0x24a43(%rip), %rdi     # 0x393cc
movl %eax, %edx
callq 0x151a6
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x24a30(%rip), %rdi     # 0x393d1
callq 0x14600
testl %eax, %eax
je 0x149d7
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x17203
movq 0x8(%rsp), %rsi
leaq 0x24a21(%rip), %rdi     # 0x393e7
movl %eax, %edx
callq 0x151a6
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x24a0f(%rip), %rdi     # 0x393ed
callq 0x14600
testl %eax, %eax
je 0x14a18
movq %rbp, %rdi
leaq 0x24a02(%rip), %rsi     # 0x393f3
movq %rbx, %rdx
xorl %eax, %eax
callq 0x17203
movq 0x8(%rsp), %rsi
leaq 0x249fc(%rip), %rdi     # 0x39403
movl %eax, %edx
callq 0x151a6
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x249ea(%rip), %rdi     # 0x39409
callq 0x14600
testl %eax, %eax
je 0x14a56
movq %rbp, %rdi
leaq 0x249dc(%rip), %rsi     # 0x3940e
xorl %eax, %eax
callq 0x17203
movq 0x8(%rsp), %rsi
leaq 0x249d5(%rip), %rdi     # 0x3941a
movl %eax, %edx
callq 0x151a6
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x249c2(%rip), %rdi     # 0x3941f
callq 0x14600
testl %eax, %eax
je 0x14a94
movq %rbp, %rdi
leaq 0x249b4(%rip), %rsi     # 0x39424
xorl %eax, %eax
callq 0x17203
movq 0x8(%rsp), %rsi
leaq 0x249ad(%rip), %rdi     # 0x39430
movl %eax, %edx
callq 0x151a6
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x2499a(%rip), %rdi     # 0x39435
callq 0x14600
testl %eax, %eax
je 0x14ad2
movq %rbp, %rdi
leaq 0x2498c(%rip), %rsi     # 0x3943a
xorl %eax, %eax
callq 0x17203
movq 0x8(%rsp), %rsi
leaq 0x24999(%rip), %rdi     # 0x3945a
movl %eax, %edx
callq 0x151a6
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x24986(%rip), %rdi     # 0x3945f
callq 0x14600
testl %eax, %eax
je 0x14b10
movq %rbp, %rdi
leaq 0x24978(%rip), %rsi     # 0x39464
xorl %eax, %eax
callq 0x17203
movq 0x8(%rsp), %rsi
leaq 0x24970(%rip), %rdi     # 0x3946f
movl %eax, %edx
callq 0x151a6
movq 0x8(%rsp), %rdi
callq 0xb050
movq %r12, %rdi
callq 0x14600
testl %eax, %eax
jne 0x14b5c
leaq 0x24958(%rip), %rdi     # 0x3947b
callq 0x14600
testl %eax, %eax
jne 0x14b5c
leaq 0x24953(%rip), %rdi     # 0x39486
callq 0x14600
testl %eax, %eax
jne 0x14b5c
leaq 0x2494e(%rip), %rdi     # 0x39491
callq 0x14600
testl %eax, %eax
jne 0x14b5c
leaq 0x24949(%rip), %rdi     # 0x3949c
callq 0x14600
testl %eax, %eax
je 0x14b89
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x17203
movq 0x8(%rsp), %rsi
leaq 0x2492f(%rip), %rdi     # 0x394a7
movl %eax, %edx
callq 0x151a6
movq 0x8(%rsp), %rdi
callq 0xb050
movq %r12, %rdi
callq 0x14600
testl %eax, %eax
jne 0x14ba5
leaq 0x248df(%rip), %rdi     # 0x3947b
callq 0x14600
testl %eax, %eax
je 0x14bd3
movq %rbp, %rdi
leaq 0x2491b(%rip), %rsi     # 0x394ca
xorl %eax, %eax
callq 0x17203
movq 0x8(%rsp), %rsi
leaq 0x2491b(%rip), %rdi     # 0x394dd
movl %eax, %edx
callq 0x151a6
movq 0x8(%rsp), %rdi
callq 0xb050
movq %r12, %rdi
callq 0x14600
testl %eax, %eax
jne 0x14bef
leaq 0x248a0(%rip), %rdi     # 0x39486
callq 0x14600
testl %eax, %eax
je 0x14c1d
movq %rbp, %rdi
leaq 0x24904(%rip), %rsi     # 0x394fd
xorl %eax, %eax
callq 0x17203
movq 0x8(%rsp), %rsi
leaq 0x24905(%rip), %rdi     # 0x39511
movl %eax, %edx
callq 0x151a6
movq 0x8(%rsp), %rdi
callq 0xb050
movq %r12, %rdi
callq 0x14600
testl %eax, %eax
jne 0x14c39
leaq 0x24861(%rip), %rdi     # 0x39491
callq 0x14600
testl %eax, %eax
je 0x14c67
movq %rbp, %rdi
leaq 0x248ee(%rip), %rsi     # 0x39531
xorl %eax, %eax
callq 0x17203
movq 0x8(%rsp), %rsi
leaq 0x248ef(%rip), %rdi     # 0x39545
movl %eax, %edx
callq 0x151a6
movq 0x8(%rsp), %rdi
callq 0xb050
movq %r12, %rdi
callq 0x14600
testl %eax, %eax
jne 0x14c83
leaq 0x24822(%rip), %rdi     # 0x3949c
callq 0x14600
testl %eax, %eax
je 0x14cb1
movq %rbp, %rdi
leaq 0x248d8(%rip), %rsi     # 0x39565
xorl %eax, %eax
callq 0x17203
movq 0x8(%rsp), %rsi
leaq 0x248d9(%rip), %rdi     # 0x39579
movl %eax, %edx
callq 0x151a6
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x248e1(%rip), %rdi     # 0x39599
callq 0x14600
testl %eax, %eax
je 0x14d19
leaq 0x248d6(%rip), %rax     # 0x3959e
movq %rax, 0x10(%rsp)
movq $-0x1, %rax
movq %r14, 0x20(%rsp,%rax,8)
movq %rbx, 0x28(%rsp,%rax,8)
addq $0x2, %rax
cmpq $0x13, %rax
jb 0x14cd4
movq %rbp, %rdi
movl $0x15, %esi
leaq 0x10(%rsp), %rdx
xorl %ecx, %ecx
callq 0x17287
movq 0x8(%rsp), %rsi
leaq 0x2489b(%rip), %rdi     # 0x395a3
movl %eax, %edx
callq 0x151a6
movq 0x8(%rsp), %rdi
callq 0xb050
cmpl $0x0, 0x37794(%rip)     # 0x4c4b4
jne 0x14d2c
movl $0xa, %edi
callq 0xb060
cmpl $0x0, 0x37785(%rip)     # 0x4c4b8
jne 0x1483b
jmp 0x14dd1
movslq %ebp, %rax
subl %eax, %ebx
leaq (%r14,%rax,8), %r14
movq (%r14), %rdi
callq 0x18492
movq %rax, %r15
cmpl $0x2, %ebx
jl 0x14d9b
movl %ebx, %ebp
movl $0x1, %r12d
movl $0x1, %edx
movq %r15, %rdi
leaq 0x25fda(%rip), %rsi     # 0x3ad48
callq 0x18c9d
movq %rax, %r15
movq (%r14,%r12,8), %r13
movq %r13, %rdi
callq 0xb190
movq %r15, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x18c9d
movq %rax, %r15
incq %r12
cmpq %r12, %rbp
jne 0x14d5f
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movl %ebx, %esi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x17287
movq 0x8(%rsp), %rsi
movq %r15, %rdi
movl %eax, %edx
callq 0x151a6
movq 0x8(%rsp), %rdi
callq 0xb050
cmpl $0x0, 0x376e9(%rip)     # 0x4c4b8
jne 0x14da0
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq