// File: /workspace/github_c_makefile_star2_O2/erikdubbelboer[P]discnt/src/discnt-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.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 = 5262;
    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("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 (!config.csv) printf("\n");
    } while(config.loop);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r15
movl %edi, %ebx
xorl %edi, %edi
callq 0xa340
movl %eax, %edi
callq 0xa090
pushq $0x1
popq %rdi
pushq $0x1
popq %r14
movq %r14, %rsi
callq 0xa2e0
pushq $0xd
popq %rdi
movq %r14, %rsi
callq 0xa2e0
movq $0x32, 0x37073(%rip) # 0x43408
movl $0x186a0, 0x37071(%rip) # imm = 0x186A0
movl $0x2800, %edi           # imm = 0x2800
callq 0xa6fc
movq %rax, 0x37038(%rip)     # 0x433e8
leaq -0x1cf(%rip), %rdx      # 0xc1e8
movq %rax, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xaa8a
movl $0x1, 0x3705f(%rip)     # 0x43430
movaps 0x24dc8(%rip), %xmm0    # 0x311a0
movups %xmm0, 0x37041(%rip)    # 0x43420
andq $0x0, 0x37061(%rip)     # 0x43448
xorps %xmm0, %xmm0
movups %xmm0, 0x3706f(%rip)    # 0x43460
callq 0xd07c
movq %rax, 0x3705b(%rip)     # 0x43458
leaq 0x24e56(%rip), %rax     # 0x3125a
movq %rax, 0x36fe5(%rip)     # 0x433f0
movl $0x148e, 0x36fe3(%rip)  # imm = 0x148E
andq $0x0, 0x36fe3(%rip)     # 0x43400
andl $0x0, 0x3704c(%rip)     # 0x43470
xorps %xmm0, %xmm0
movups %xmm0, 0x37052(%rip)    # 0x43480
movl %ebx, %edi
movq %r15, %rsi
callq 0xbe04
movl %eax, %ebp
movslq 0x36fcf(%rip), %rdi     # 0x43410
shlq $0x3, %rdi
callq 0xd415
movq %rax, 0x36ff7(%rip)     # 0x43448
cmpl $0x0, 0x36fd4(%rip)     # 0x4342c
jne 0xc466
leaq 0x258ca(%rip), %rdi     # 0x31d2b
callq 0xa0d0
cmpl $0x0, 0x36fff(%rip)     # 0x4346c
je 0xc4a7
movl 0x36f93(%rip), %esi     # 0x43408
leaq 0x24de8(%rip), %rdi     # 0x31264
xorl %eax, %eax
callq 0xa1b0
leaq 0x2501c(%rip), %rdi     # 0x314a6
xorl %esi, %esi
xorl %edx, %edx
callq 0xc6b4
movq %rax, %rdi
callq 0xc9c5
movq 0x36f46(%rip), %rdi     # 0x433e8
callq 0xaf46
cmpl %ebp, %ebx
jne 0xc60c
movslq 0x36f6a(%rip), %rdi     # 0x43420
incq %rdi
callq 0xd415
movq %rax, %rbx
leaq 0x24e05(%rip), %r12     # 0x312cd
leaq 0x24e18(%rip), %r13     # 0x312e7
leaq 0x24e2e(%rip), %r15     # 0x31304
leaq 0x8(%rsp), %rbp
movslq 0x36f3e(%rip), %r14     # 0x43420
movq %rbx, %rdi
pushq $0x78
popq %rsi
movq %r14, %rdx
callq 0xa220
movb $0x0, (%rbx,%r14)
leaq 0x24dad(%rip), %rdi     # 0x312a9
callq 0xc2bd
testl %eax, %eax
jne 0xc515
leaq 0x24da9(%rip), %rdi     # 0x312b5
callq 0xc2bd
testl %eax, %eax
je 0xc52b
leaq 0x24d9e(%rip), %rdi     # 0x312ba
leaq 0x24da3(%rip), %rsi     # 0x312c6
pushq $0x6
popq %rdx
callq 0xca0a
movq %r12, %rdi
callq 0xc2bd
testl %eax, %eax
jne 0xc547
leaq 0x24d77(%rip), %rdi     # 0x312b5
callq 0xc2bd
testl %eax, %eax
je 0xc575
movq %rbp, %rdi
leaq 0x24d87(%rip), %rsi     # 0x312d8
xorl %eax, %eax
callq 0xe701
movq 0x8(%rsp), %rsi
leaq 0x24d79(%rip), %rdi     # 0x312dd
movl %eax, %edx
callq 0xca0a
movq 0x8(%rsp), %rdi
callq 0xa050
movq %r13, %rdi
callq 0xc2bd
testl %eax, %eax
je 0xc5af
movq %rbp, %rdi
leaq 0x24d60(%rip), %rsi     # 0x312eb
xorl %eax, %eax
callq 0xe701
movq 0x8(%rsp), %rsi
leaq 0x24d62(%rip), %rdi     # 0x31300
movl %eax, %edx
callq 0xca0a
movq 0x8(%rsp), %rdi
callq 0xa050
movq %r15, %rdi
callq 0xc2bd
testl %eax, %eax
je 0xc5e9
movq %rbp, %rdi
leaq 0x24d44(%rip), %rsi     # 0x31309
xorl %eax, %eax
callq 0xe701
movq 0x8(%rsp), %rsi
leaq 0x24d4b(%rip), %rdi     # 0x31323
movl %eax, %edx
callq 0xca0a
movq 0x8(%rsp), %rdi
callq 0xa050
cmpl $0x0, 0x36e74(%rip)     # 0x43464
jne 0xc5fa
pushq $0xa
popq %rdi
callq 0xa060
cmpl $0x0, 0x36e67(%rip)     # 0x43468
jne 0xc4db
jmp 0xc6a3
movslq %ebp, %rax
subl %eax, %ebx
leaq (%r15,%rax,8), %r15
movq (%r15), %rdi
callq 0xf62e
movq %rax, %r12
movl %ebx, 0x14(%rsp)
movslq %ebx, %r14
leaq 0x25fcf(%rip), %r13     # 0x325fd
pushq $0x1
popq %rbx
cmpq %r14, %rbx
jge 0xc669
movq %r12, %rdi
movq %r13, %rsi
pushq $0x1
popq %rdx
callq 0xfc2c
movq %rax, %r12
movq (%r15,%rbx,8), %rbp
movq %rbp, %rdi
callq 0xa180
movq %r12, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0xfc2c
movq %rax, %r12
incq %rbx
jmp 0xc631
leaq 0x8(%rsp), %r14
movl 0x14(%rsp), %ebx
movq %r14, %rdi
movl %ebx, %esi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xe785
movq 0x8(%rsp), %rsi
movq %r12, %rdi
movl %eax, %edx
callq 0xca0a
movq 0x8(%rsp), %rdi
callq 0xa050
cmpl $0x0, 0x36dc7(%rip)     # 0x43468
jne 0xc672
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq