// File: /workspace/github_c_makefile_star2_O2/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, %r15
movl %edi, %ebx
xorl %edi, %edi
callq 0xb350
movl %eax, %edi
callq 0xb090
pushq $0x1
popq %rdi
pushq $0x1
popq %r14
movq %r14, %rsi
callq 0xb2f0
pushq $0xd
popq %rdi
movq %r14, %rsi
callq 0xb2f0
movq $0x32, 0x3b022(%rip) # 0x48458
movl $0x186a0, 0x3b020(%rip) # imm = 0x186A0
movl $0x2800, %edi           # imm = 0x2800
callq 0xb70c
movq %rax, 0x3afe7(%rip)     # 0x48438
leaq -0x1d2(%rip), %rdx      # 0xd286
movq %rax, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xba8e
movq $0x1, 0x3b00d(%rip) # 0x48480
movaps 0x26d36(%rip), %xmm0    # 0x341b0
movups %xmm0, 0x3afef(%rip)    # 0x48470
andq $0x0, 0x3b00f(%rip)     # 0x48498
xorps %xmm0, %xmm0
movups %xmm0, 0x3b01d(%rip)    # 0x484b0
callq 0xe50c
movq %rax, 0x3b009(%rip)     # 0x484a8
leaq 0x26dc4(%rip), %rax     # 0x3426a
movq %rax, 0x3af93(%rip)     # 0x48440
movl $0x18eb, 0x3af91(%rip)  # imm = 0x18EB
andq $0x0, 0x3af91(%rip)     # 0x48450
andl $0x0, 0x3affa(%rip)     # 0x484c0
xorps %xmm0, %xmm0
movups %xmm0, 0x3b000(%rip)    # 0x484d0
movl %ebx, %edi
movq %r15, %rsi
callq 0xce70
movl %eax, %ebp
movslq 0x3af7d(%rip), %rdi     # 0x48460
shlq $0x3, %rdi
callq 0xe87d
movq %rax, 0x3afa5(%rip)     # 0x48498
cmpl $0x0, 0x3af82(%rip)     # 0x4847c
jne 0xd508
leaq 0x27b49(%rip), %rdi     # 0x3504c
callq 0xb0d0
cmpl $0x0, 0x3afad(%rip)     # 0x484bc
je 0xd549
movl 0x3af41(%rip), %esi     # 0x48458
leaq 0x26d56(%rip), %rdi     # 0x34274
xorl %eax, %eax
callq 0xb1c0
leaq 0x27198(%rip), %rdi     # 0x346c4
xorl %esi, %esi
xorl %edx, %edx
callq 0xdafb
movq %rax, %rdi
callq 0xde0c
movq 0x3aef4(%rip), %rdi     # 0x48438
callq 0xbf4a
cmpl %ebp, %ebx
jne 0xda54
movslq 0x3af18(%rip), %rdi     # 0x48470
incq %rdi
callq 0xe87d
movq %rax, %rbx
leaq 0x26e89(%rip), %r12     # 0x343f3
leaq 0x26da6(%rip), %r14     # 0x34317
movq %rsp, %r15
leaq 0x26ddb(%rip), %rbp     # 0x34356
movslq 0x3aeee(%rip), %r13     # 0x48470
movq %rbx, %rdi
pushq $0x78
popq %rsi
movq %r13, %rdx
callq 0xb230
movb $0x0, (%rbx,%r13)
leaq 0x26d1d(%rip), %rdi     # 0x342b9
callq 0xd35b
testl %eax, %eax
jne 0xd5b5
leaq 0x26d19(%rip), %rdi     # 0x342c5
callq 0xd35b
testl %eax, %eax
je 0xd5cb
leaq 0x26d0e(%rip), %rdi     # 0x342ca
leaq 0x26d13(%rip), %rsi     # 0x342d6
pushq $0x6
popq %rdx
callq 0xde51
leaq 0x26d0b(%rip), %rdi     # 0x342dd
callq 0xd35b
testl %eax, %eax
jne 0xd5eb
leaq 0x26ce3(%rip), %rdi     # 0x342c5
callq 0xd35b
testl %eax, %eax
je 0xd617
movq %r15, %rdi
leaq 0x26cf3(%rip), %rsi     # 0x342e8
xorl %eax, %eax
callq 0xfb51
movq (%rsp), %rsi
leaq 0x26ce6(%rip), %rdi     # 0x342ed
movl %eax, %edx
callq 0xde51
movq (%rsp), %rdi
callq 0xb050
leaq 0x2a0e2(%rip), %rdi     # 0x37700
callq 0xd35b
testl %eax, %eax
je 0xd656
movq %r15, %rdi
leaq 0x26cc6(%rip), %rsi     # 0x342f7
movq %rbx, %rdx
xorl %eax, %eax
callq 0xfb51
movq (%rsp), %rsi
leaq 0x26ed8(%rip), %rdi     # 0x3451e
movl %eax, %edx
callq 0xde51
movq (%rsp), %rdi
callq 0xb050
leaq 0x26cb2(%rip), %rdi     # 0x3430f
callq 0xd35b
testl %eax, %eax
je 0xd692
movq %r15, %rdi
leaq 0x26ca3(%rip), %rsi     # 0x34313
xorl %eax, %eax
callq 0xfb51
movq (%rsp), %rsi
leaq 0x26ca6(%rip), %rdi     # 0x34328
movl %eax, %edx
callq 0xde51
movq (%rsp), %rdi
callq 0xb050
leaq 0x26c93(%rip), %rdi     # 0x3432c
callq 0xd35b
testl %eax, %eax
je 0xd6ce
movq %r15, %rdi
leaq 0x26c85(%rip), %rsi     # 0x34331
xorl %eax, %eax
callq 0xfb51
movq (%rsp), %rsi
leaq 0x26c8d(%rip), %rdi     # 0x3434b
movl %eax, %edx
callq 0xde51
movq (%rsp), %rdi
callq 0xb050
leaq 0x26c7b(%rip), %rdi     # 0x34350
callq 0xd35b
testl %eax, %eax
je 0xd709
movq %r15, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xfb51
movq (%rsp), %rsi
leaq 0x26c6d(%rip), %rdi     # 0x34366
movl %eax, %edx
callq 0xde51
movq (%rsp), %rdi
callq 0xb050
leaq 0x26c5c(%rip), %rdi     # 0x3436c
callq 0xd35b
testl %eax, %eax
je 0xd748
movq %r15, %rdi
leaq 0x26c4f(%rip), %rsi     # 0x34372
movq %rbx, %rdx
xorl %eax, %eax
callq 0xfb51
movq (%rsp), %rsi
leaq 0x26c4a(%rip), %rdi     # 0x34382
movl %eax, %edx
callq 0xde51
movq (%rsp), %rdi
callq 0xb050
leaq 0x26c39(%rip), %rdi     # 0x34388
callq 0xd35b
testl %eax, %eax
je 0xd784
movq %r15, %rdi
leaq 0x26c2b(%rip), %rsi     # 0x3438d
xorl %eax, %eax
callq 0xfb51
movq (%rsp), %rsi
leaq 0x26c25(%rip), %rdi     # 0x34399
movl %eax, %edx
callq 0xde51
movq (%rsp), %rdi
callq 0xb050
leaq 0x26c13(%rip), %rdi     # 0x3439e
callq 0xd35b
testl %eax, %eax
je 0xd7c0
movq %r15, %rdi
leaq 0x26c05(%rip), %rsi     # 0x343a3
xorl %eax, %eax
callq 0xfb51
movq (%rsp), %rsi
leaq 0x26bff(%rip), %rdi     # 0x343af
movl %eax, %edx
callq 0xde51
movq (%rsp), %rdi
callq 0xb050
leaq 0x26bed(%rip), %rdi     # 0x343b4
callq 0xd35b
testl %eax, %eax
je 0xd7fc
movq %r15, %rdi
leaq 0x26bdf(%rip), %rsi     # 0x343b9
xorl %eax, %eax
callq 0xfb51
movq (%rsp), %rsi
leaq 0x26bed(%rip), %rdi     # 0x343d9
movl %eax, %edx
callq 0xde51
movq (%rsp), %rdi
callq 0xb050
leaq 0x26bdb(%rip), %rdi     # 0x343de
callq 0xd35b
testl %eax, %eax
je 0xd838
movq %r15, %rdi
leaq 0x26bcd(%rip), %rsi     # 0x343e3
xorl %eax, %eax
callq 0xfb51
movq (%rsp), %rsi
leaq 0x26bc6(%rip), %rdi     # 0x343ee
movl %eax, %edx
callq 0xde51
movq (%rsp), %rdi
callq 0xb050
movq %r12, %rdi
callq 0xd35b
testl %eax, %eax
jne 0xd884
leaq 0x26baf(%rip), %rdi     # 0x343fa
callq 0xd35b
testl %eax, %eax
jne 0xd884
leaq 0x26baa(%rip), %rdi     # 0x34405
callq 0xd35b
testl %eax, %eax
jne 0xd884
leaq 0x26ba5(%rip), %rdi     # 0x34410
callq 0xd35b
testl %eax, %eax
jne 0xd884
leaq 0x26ba0(%rip), %rdi     # 0x3441b
callq 0xd35b
testl %eax, %eax
je 0xd8af
movq %r15, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xfb51
movq (%rsp), %rsi
leaq 0x26b87(%rip), %rdi     # 0x34426
movl %eax, %edx
callq 0xde51
movq (%rsp), %rdi
callq 0xb050
movq %r12, %rdi
callq 0xd35b
testl %eax, %eax
jne 0xd8cb
leaq 0x26b38(%rip), %rdi     # 0x343fa
callq 0xd35b
testl %eax, %eax
je 0xd8f7
movq %r15, %rdi
leaq 0x26b74(%rip), %rsi     # 0x34449
xorl %eax, %eax
callq 0xfb51
movq (%rsp), %rsi
leaq 0x26b75(%rip), %rdi     # 0x3445c
movl %eax, %edx
callq 0xde51
movq (%rsp), %rdi
callq 0xb050
movq %r12, %rdi
callq 0xd35b
testl %eax, %eax
jne 0xd913
leaq 0x26afb(%rip), %rdi     # 0x34405
callq 0xd35b
testl %eax, %eax
je 0xd93f
movq %r15, %rdi
leaq 0x26b5f(%rip), %rsi     # 0x3447c
xorl %eax, %eax
callq 0xfb51
movq (%rsp), %rsi
leaq 0x26b61(%rip), %rdi     # 0x34490
movl %eax, %edx
callq 0xde51
movq (%rsp), %rdi
callq 0xb050
movq %r12, %rdi
callq 0xd35b
testl %eax, %eax
jne 0xd95b
leaq 0x26abe(%rip), %rdi     # 0x34410
callq 0xd35b
testl %eax, %eax
je 0xd987
movq %r15, %rdi
leaq 0x26b4b(%rip), %rsi     # 0x344b0
xorl %eax, %eax
callq 0xfb51
movq (%rsp), %rsi
leaq 0x26b4d(%rip), %rdi     # 0x344c4
movl %eax, %edx
callq 0xde51
movq (%rsp), %rdi
callq 0xb050
movq %r12, %rdi
callq 0xd35b
testl %eax, %eax
jne 0xd9a3
leaq 0x26a81(%rip), %rdi     # 0x3441b
callq 0xd35b
testl %eax, %eax
je 0xd9cf
movq %r15, %rdi
leaq 0x26b37(%rip), %rsi     # 0x344e4
xorl %eax, %eax
callq 0xfb51
movq (%rsp), %rsi
leaq 0x26b39(%rip), %rdi     # 0x344f8
movl %eax, %edx
callq 0xde51
movq (%rsp), %rdi
callq 0xb050
leaq 0x26b42(%rip), %rdi     # 0x34518
callq 0xd35b
testl %eax, %eax
je 0xda31
leaq 0x26b37(%rip), %rax     # 0x3451d
movq %rax, 0x10(%rsp)
pushq $0x1
popq %rax
cmpq $0x14, %rax
ja 0xda04
movq %r14, 0x10(%rsp,%rax,8)
movq %rbx, 0x18(%rsp,%rax,8)
addq $0x2, %rax
jmp 0xd9ee
movq %r15, %rdi
pushq $0x15
popq %rsi
leaq 0x10(%rsp), %rdx
xorl %ecx, %ecx
callq 0xfbd5
movq (%rsp), %rsi
leaq 0x26b01(%rip), %rdi     # 0x34522
movl %eax, %edx
callq 0xde51
movq (%rsp), %rdi
callq 0xb050
cmpl $0x0, 0x3aa7c(%rip)     # 0x484b4
jne 0xda42
pushq $0xa
popq %rdi
callq 0xb060
cmpl $0x0, 0x3aa6f(%rip)     # 0x484b8
jne 0xd57b
jmp 0xdae7
movslq %ebp, %rax
subl %eax, %ebx
leaq (%r15,%rax,8), %r15
movq (%r15), %rdi
callq 0x10a7e
movq %rax, %r12
movl %ebx, 0xc(%rsp)
movslq %ebx, %r14
leaq 0x27eab(%rip), %r13     # 0x35921
pushq $0x1
popq %rbx
cmpq %r14, %rbx
jge 0xdab1
movq %r12, %rdi
movq %r13, %rsi
pushq $0x1
popq %rdx
callq 0x1107c
movq %rax, %r12
movq (%r15,%rbx,8), %rbp
movq %rbp, %rdi
callq 0xb190
movq %r12, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x1107c
movq %rax, %r12
incq %rbx
jmp 0xda79
movq %rsp, %r14
movl 0xc(%rsp), %ebx
movq %r14, %rdi
movl %ebx, %esi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xfbd5
movq (%rsp), %rsi
movq %r12, %rdi
movl %eax, %edx
callq 0xde51
movq (%rsp), %rdi
callq 0xb050
cmpl $0x0, 0x3a9d3(%rip)     # 0x484b8
jne 0xdab8
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq