// File: /workspace/github_c_makefile_star2_O3/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, 0x37fa2(%rip) # 0x4c458
movl $0x186a0, 0x37fa0(%rip) # imm = 0x186A0
movl $0x2800, %edi           # imm = 0x2800
callq 0x1235c
movq %rax, 0x37f67(%rip)     # 0x4c438
leaq -0x1cd(%rip), %rdx      # 0x1430b
movl $0x1, %esi
movq %rax, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x12903
movq $0x1, 0x37f8b(%rip) # 0x4c480
movaps 0x24d04(%rip), %xmm0    # 0x39200
movups %xmm0, 0x37f6d(%rip)    # 0x4c470
movq %r15, 0x37f8e(%rip)     # 0x4c498
xorps %xmm0, %xmm0
movups %xmm0, 0x37f9c(%rip)    # 0x4c4b0
callq 0x1572c
movq %rax, 0x37f88(%rip)     # 0x4c4a8
leaq 0x24df7(%rip), %rax     # 0x3931e
movq %rax, 0x37f12(%rip)     # 0x4c440
movl $0x18eb, 0x37f10(%rip)  # imm = 0x18EB
movq %r15, 0x37f11(%rip)     # 0x4c450
movl $0x0, 0x37f77(%rip)     # 0x4c4c0
xorps %xmm0, %xmm0
movups %xmm0, 0x37f7d(%rip)    # 0x4c4d0
movl %ebx, %edi
movq %r14, %rsi
callq 0x13ea4
movl %eax, %ebp
movslq 0x37efa(%rip), %rdi     # 0x4c460
shlq $0x3, %rdi
callq 0x15ae5
movq %rax, 0x37f22(%rip)     # 0x4c498
cmpl $0x0, 0x37eff(%rip)     # 0x4c47c
jne 0x1458b
leaq 0x25b7a(%rip), %rdi     # 0x3a100
callq 0xb0d0
cmpl $0x0, 0x37f2a(%rip)     # 0x4c4bc
je 0x145cc
movl 0x37ebe(%rip), %esi     # 0x4c458
leaq 0x24d87(%rip), %rdi     # 0x39328
xorl %eax, %eax
callq 0xb1c0
leaq 0x251c9(%rip), %rdi     # 0x39778
xorl %esi, %esi
xorl %edx, %edx
callq 0x14baa
movq %rax, %rdi
callq 0x14f29
movq 0x37e71(%rip), %rdi     # 0x4c438
callq 0x12e5b
cmpl %ebp, %ebx
jne 0x14b03
movslq 0x37e95(%rip), %rdi     # 0x4c470
incq %rdi
callq 0x15ae5
movq %rax, %rbx
leaq 0x24eba(%rip), %r12     # 0x394a7
leaq 0x24dd7(%rip), %r14     # 0x393cb
leaq 0x8(%rsp), %rbp
leaq 0x24e0a(%rip), %r15     # 0x3940a
movslq 0x37e69(%rip), %r13     # 0x4c470
movq %rbx, %rdi
movl $0x78, %esi
movq %r13, %rdx
callq 0xb230
movb $0x0, (%rbx,%r13)
leaq 0x24d4a(%rip), %rdi     # 0x3936d
callq 0x143d2
testl %eax, %eax
jne 0x1463c
leaq 0x24d46(%rip), %rdi     # 0x39379
callq 0x143d2
testl %eax, %eax
je 0x14654
leaq 0x24d3b(%rip), %rdi     # 0x3937e
leaq 0x24d40(%rip), %rsi     # 0x3938a
movl $0x6, %edx
callq 0x14f7b
leaq 0x24d36(%rip), %rdi     # 0x39391
callq 0x143d2
testl %eax, %eax
jne 0x14674
leaq 0x24d0e(%rip), %rdi     # 0x39379
callq 0x143d2
testl %eax, %eax
je 0x146a2
movq %rbp, %rdi
leaq 0x24d1e(%rip), %rsi     # 0x3939c
xorl %eax, %eax
callq 0x16f79
movq 0x8(%rsp), %rsi
leaq 0x24d10(%rip), %rdi     # 0x393a1
movl %eax, %edx
callq 0x14f7b
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x284f6(%rip), %rdi     # 0x3cb9f
callq 0x143d2
testl %eax, %eax
je 0x146e3
movq %rbp, %rdi
leaq 0x24cef(%rip), %rsi     # 0x393ab
movq %rbx, %rdx
xorl %eax, %eax
callq 0x16f79
movq 0x8(%rsp), %rsi
leaq 0x24f00(%rip), %rdi     # 0x395d2
movl %eax, %edx
callq 0x14f7b
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x24cd9(%rip), %rdi     # 0x393c3
callq 0x143d2
testl %eax, %eax
je 0x14721
movq %rbp, %rdi
leaq 0x24cca(%rip), %rsi     # 0x393c7
xorl %eax, %eax
callq 0x16f79
movq 0x8(%rsp), %rsi
leaq 0x24ccc(%rip), %rdi     # 0x393dc
movl %eax, %edx
callq 0x14f7b
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x24cb8(%rip), %rdi     # 0x393e0
callq 0x143d2
testl %eax, %eax
je 0x1475f
movq %rbp, %rdi
leaq 0x24caa(%rip), %rsi     # 0x393e5
xorl %eax, %eax
callq 0x16f79
movq 0x8(%rsp), %rsi
leaq 0x24cb1(%rip), %rdi     # 0x393ff
movl %eax, %edx
callq 0x14f7b
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x24c9e(%rip), %rdi     # 0x39404
callq 0x143d2
testl %eax, %eax
je 0x1479c
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x16f79
movq 0x8(%rsp), %rsi
leaq 0x24c8f(%rip), %rdi     # 0x3941a
movl %eax, %edx
callq 0x14f7b
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x24c7d(%rip), %rdi     # 0x39420
callq 0x143d2
testl %eax, %eax
je 0x147dd
movq %rbp, %rdi
leaq 0x24c70(%rip), %rsi     # 0x39426
movq %rbx, %rdx
xorl %eax, %eax
callq 0x16f79
movq 0x8(%rsp), %rsi
leaq 0x24c6a(%rip), %rdi     # 0x39436
movl %eax, %edx
callq 0x14f7b
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x24c58(%rip), %rdi     # 0x3943c
callq 0x143d2
testl %eax, %eax
je 0x1481b
movq %rbp, %rdi
leaq 0x24c4a(%rip), %rsi     # 0x39441
xorl %eax, %eax
callq 0x16f79
movq 0x8(%rsp), %rsi
leaq 0x24c43(%rip), %rdi     # 0x3944d
movl %eax, %edx
callq 0x14f7b
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x24c30(%rip), %rdi     # 0x39452
callq 0x143d2
testl %eax, %eax
je 0x14859
movq %rbp, %rdi
leaq 0x24c22(%rip), %rsi     # 0x39457
xorl %eax, %eax
callq 0x16f79
movq 0x8(%rsp), %rsi
leaq 0x24c1b(%rip), %rdi     # 0x39463
movl %eax, %edx
callq 0x14f7b
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x24c08(%rip), %rdi     # 0x39468
callq 0x143d2
testl %eax, %eax
je 0x14897
movq %rbp, %rdi
leaq 0x24bfa(%rip), %rsi     # 0x3946d
xorl %eax, %eax
callq 0x16f79
movq 0x8(%rsp), %rsi
leaq 0x24c07(%rip), %rdi     # 0x3948d
movl %eax, %edx
callq 0x14f7b
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x24bf4(%rip), %rdi     # 0x39492
callq 0x143d2
testl %eax, %eax
je 0x148d5
movq %rbp, %rdi
leaq 0x24be6(%rip), %rsi     # 0x39497
xorl %eax, %eax
callq 0x16f79
movq 0x8(%rsp), %rsi
leaq 0x24bde(%rip), %rdi     # 0x394a2
movl %eax, %edx
callq 0x14f7b
movq 0x8(%rsp), %rdi
callq 0xb050
movq %r12, %rdi
callq 0x143d2
testl %eax, %eax
jne 0x14921
leaq 0x24bc6(%rip), %rdi     # 0x394ae
callq 0x143d2
testl %eax, %eax
jne 0x14921
leaq 0x24bc1(%rip), %rdi     # 0x394b9
callq 0x143d2
testl %eax, %eax
jne 0x14921
leaq 0x24bbc(%rip), %rdi     # 0x394c4
callq 0x143d2
testl %eax, %eax
jne 0x14921
leaq 0x24bb7(%rip), %rdi     # 0x394cf
callq 0x143d2
testl %eax, %eax
je 0x1494e
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x16f79
movq 0x8(%rsp), %rsi
leaq 0x24b9d(%rip), %rdi     # 0x394da
movl %eax, %edx
callq 0x14f7b
movq 0x8(%rsp), %rdi
callq 0xb050
movq %r12, %rdi
callq 0x143d2
testl %eax, %eax
jne 0x1496a
leaq 0x24b4d(%rip), %rdi     # 0x394ae
callq 0x143d2
testl %eax, %eax
je 0x14998
movq %rbp, %rdi
leaq 0x24b89(%rip), %rsi     # 0x394fd
xorl %eax, %eax
callq 0x16f79
movq 0x8(%rsp), %rsi
leaq 0x24b89(%rip), %rdi     # 0x39510
movl %eax, %edx
callq 0x14f7b
movq 0x8(%rsp), %rdi
callq 0xb050
movq %r12, %rdi
callq 0x143d2
testl %eax, %eax
jne 0x149b4
leaq 0x24b0e(%rip), %rdi     # 0x394b9
callq 0x143d2
testl %eax, %eax
je 0x149e2
movq %rbp, %rdi
leaq 0x24b72(%rip), %rsi     # 0x39530
xorl %eax, %eax
callq 0x16f79
movq 0x8(%rsp), %rsi
leaq 0x24b73(%rip), %rdi     # 0x39544
movl %eax, %edx
callq 0x14f7b
movq 0x8(%rsp), %rdi
callq 0xb050
movq %r12, %rdi
callq 0x143d2
testl %eax, %eax
jne 0x149fe
leaq 0x24acf(%rip), %rdi     # 0x394c4
callq 0x143d2
testl %eax, %eax
je 0x14a2c
movq %rbp, %rdi
leaq 0x24b5c(%rip), %rsi     # 0x39564
xorl %eax, %eax
callq 0x16f79
movq 0x8(%rsp), %rsi
leaq 0x24b5d(%rip), %rdi     # 0x39578
movl %eax, %edx
callq 0x14f7b
movq 0x8(%rsp), %rdi
callq 0xb050
movq %r12, %rdi
callq 0x143d2
testl %eax, %eax
jne 0x14a48
leaq 0x24a90(%rip), %rdi     # 0x394cf
callq 0x143d2
testl %eax, %eax
je 0x14a76
movq %rbp, %rdi
leaq 0x24b46(%rip), %rsi     # 0x39598
xorl %eax, %eax
callq 0x16f79
movq 0x8(%rsp), %rsi
leaq 0x24b47(%rip), %rdi     # 0x395ac
movl %eax, %edx
callq 0x14f7b
movq 0x8(%rsp), %rdi
callq 0xb050
leaq 0x24b4f(%rip), %rdi     # 0x395cc
callq 0x143d2
testl %eax, %eax
je 0x14ade
leaq 0x24b44(%rip), %rax     # 0x395d1
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 0x14a99
movq %rbp, %rdi
movl $0x15, %esi
leaq 0x10(%rsp), %rdx
xorl %ecx, %ecx
callq 0x16ffd
movq 0x8(%rsp), %rsi
leaq 0x24b09(%rip), %rdi     # 0x395d6
movl %eax, %edx
callq 0x14f7b
movq 0x8(%rsp), %rdi
callq 0xb050
cmpl $0x0, 0x379cf(%rip)     # 0x4c4b4
jne 0x14af1
movl $0xa, %edi
callq 0xb060
cmpl $0x0, 0x379c0(%rip)     # 0x4c4b8
jne 0x14600
jmp 0x14b96
movslq %ebp, %rax
subl %eax, %ebx
leaq (%r14,%rax,8), %r14
movq (%r14), %rdi
callq 0x181a9
movq %rax, %r15
cmpl $0x2, %ebx
jl 0x14b60
movl %ebx, %ebp
movl $0x1, %r12d
movl $0x1, %edx
movq %r15, %rdi
leaq 0x2624d(%rip), %rsi     # 0x3ad80
callq 0x189ce
movq %rax, %r15
movq (%r14,%r12,8), %r13
movq %r13, %rdi
callq 0xb190
movq %r15, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x189ce
movq %rax, %r15
incq %r12
cmpq %r12, %rbp
jne 0x14b24
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movl %ebx, %esi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x16ffd
movq 0x8(%rsp), %rsi
movq %r15, %rdi
movl %eax, %edx
callq 0x14f7b
movq 0x8(%rsp), %rdi
callq 0xb050
cmpl $0x0, 0x37924(%rip)     # 0x4c4b8
jne 0x14b65
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq