// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/server.c
// Function: main
int main(int argc, char **argv) {
    struct timeval tv;
    int j;

#ifdef REDIS_TEST
    if (argc == 3 && !strcasecmp(argv[1], "test")) {
        if (!strcasecmp(argv[2], "ziplist")) {
            return ziplistTest(argc, argv);
        } else if (!strcasecmp(argv[2], "quicklist")) {
            quicklistTest(argc, argv);
        } else if (!strcasecmp(argv[2], "intset")) {
            return intsetTest(argc, argv);
        } else if (!strcasecmp(argv[2], "zipmap")) {
            return zipmapTest(argc, argv);
        } else if (!strcasecmp(argv[2], "sha1test")) {
            return sha1Test(argc, argv);
        } else if (!strcasecmp(argv[2], "util")) {
            return utilTest(argc, argv);
        } else if (!strcasecmp(argv[2], "sds")) {
            return sdsTest(argc, argv);
        } else if (!strcasecmp(argv[2], "endianconv")) {
            return endianconvTest(argc, argv);
        } else if (!strcasecmp(argv[2], "crc64")) {
            return crc64Test(argc, argv);
        }

        return -1; /* test not found */
    }
#endif

    /* We need to initialize our libraries, and the server configuration. */
#ifdef INIT_SETPROCTITLE_REPLACEMENT
    spt_init(argc, argv);
#endif
    setlocale(LC_COLLATE,"");
    zmalloc_enable_thread_safeness();
    zmalloc_set_oom_handler(redisOutOfMemoryHandler);
    srand(time(NULL)^getpid());
    gettimeofday(&tv,NULL);
    dictSetHashFunctionSeed(tv.tv_sec^tv.tv_usec^getpid());
    server.sentinel_mode = checkForSentinelMode(argc,argv);
    initServerConfig();

    /* Store the executable path and arguments in a safe place in order
     * to be able to restart the server later. */
    server.executable = getAbsolutePath(argv[0]);
    server.exec_argv = zmalloc(sizeof(char*)*(argc+1));
    server.exec_argv[argc] = NULL;
    for (j = 0; j < argc; j++) server.exec_argv[j] = zstrdup(argv[j]);

    /* We need to init sentinel right now as parsing the configuration file
     * in sentinel mode will have the effect of populating the sentinel
     * data structures with master nodes to monitor. */
    if (server.sentinel_mode) {
        initSentinelConfig();
        initSentinel();
    }

    /* Check if we need to start in redis-check-rdb mode. We just execute
     * the program main. However the program is part of the Redis executable
     * so that we can easily execute an RDB check on loading errors. */
    if (strstr(argv[0],"redis-check-rdb") != NULL)
        redis_check_rdb_main(argc,argv);

    if (argc >= 2) {
        j = 1; /* First option to parse in argv[] */
        sds options = sdsempty();
        char *configfile = NULL;

        /* Handle special options --help and --version */
        if (strcmp(argv[1], "-v") == 0 ||
            strcmp(argv[1], "--version") == 0) version();
        if (strcmp(argv[1], "--help") == 0 ||
            strcmp(argv[1], "-h") == 0) usage();
        if (strcmp(argv[1], "--test-memory") == 0) {
            if (argc == 3) {
                memtest(atoi(argv[2]),50);
                exit(0);
            } else {
                fprintf(stderr,"Please specify the amount of memory to test in megabytes.\n");
                fprintf(stderr,"Example: ./redis-server --test-memory 4096\n\n");
                exit(1);
            }
        }

        /* First argument is the config file name? */
        if (argv[j][0] != '-' || argv[j][1] != '-') {
            configfile = argv[j];
            server.configfile = getAbsolutePath(configfile);
            /* Replace the config file in server.exec_argv with
             * its absoulte path. */
            zfree(server.exec_argv[j]);
            server.exec_argv[j] = zstrdup(server.configfile);
            j++;
        }

        /* All the other options are parsed and conceptually appended to the
         * configuration file. For instance --port 6380 will generate the
         * string "port 6380\n" to be parsed after the actual file name
         * is parsed, if any. */
        while(j != argc) {
            if (argv[j][0] == '-' && argv[j][1] == '-') {
                /* Option name */
                if (!strcmp(argv[j], "--check-rdb")) {
                    /* Argument has no options, need to skip for parsing. */
                    j++;
                    continue;
                }
                if (sdslen(options)) options = sdscat(options,"\n");
                options = sdscat(options,argv[j]+2);
                options = sdscat(options," ");
            } else {
                /* Option argument */
                options = sdscatrepr(options,argv[j],strlen(argv[j]));
                options = sdscat(options," ");
            }
            j++;
        }
        if (server.sentinel_mode && configfile && *configfile == '-') {
            serverLog(LL_WARNING,
                "Sentinel config from STDIN not allowed.");
            serverLog(LL_WARNING,
                "Sentinel needs config file on disk to save state.  Exiting...");
            exit(1);
        }
        resetServerSaveParams();
        loadServerConfig(configfile,options);
        sdsfree(options);
    } else {
        serverLog(LL_WARNING, "Warning: no config file specified, using the default config. In order to specify a config file use %s /path/to/%s.conf", argv[0], server.sentinel_mode ? "sentinel" : "redis");
    }

    server.supervised = redisIsSupervised(server.supervised_mode);
    int background = server.daemonize && !server.supervised;
    if (background) daemonize();

    initServer();
    if (background || server.pidfile) createPidFile();
    redisSetProcTitle(argv[0]);
    redisAsciiArt();
    checkTcpBacklogSettings();

    if (!server.sentinel_mode) {
        /* Things not needed when running in Sentinel mode. */
        serverLog(LL_WARNING,"Server started, Redis version " REDIS_VERSION);
    #ifdef __linux__
        linuxMemoryWarnings();
    #endif
        loadDataFromDisk();
        if (server.cluster_enabled) {
            if (verifyClusterConfigWithData() == C_ERR) {
                serverLog(LL_WARNING,
                    "You can't have keys in a DB different than DB 0 when in "
                    "Cluster mode. Exiting.");
                exit(1);
            }
        }
        if (server.ipfd_count > 0)
            serverLog(LL_NOTICE,"The server is now ready to accept connections on port %d", server.port);
        if (server.sofd > 0)
            serverLog(LL_NOTICE,"The server is now ready to accept connections at %s", server.unixsocket);
    } else {
        sentinelIsRunning();
    }

    /* Warning the user about suspicious maxmemory setting. */
    if (server.maxmemory > 0 && server.maxmemory < 1024*1024) {
        serverLog(LL_WARNING,"WARNING: You specified a maxmemory value that is less than 1MB (current value is %llu bytes). Are you sure this is what you really want?", server.maxmemory);
    }

    aeSetBeforeSleepProc(server.el,beforeSleep);
    aeMain(server.el);
    aeDeleteEventLoop(server.el);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movl %edi, %ebp
callq 0x6fcc0
leaq 0x818a6(%rip), %rsi     # 0xb2405
pushq $0x3
popq %rdi
callq 0x26b40
callq 0x32974
leaq -0x2f6(%rip), %rdi      # 0x3087d
callq 0x3297c
xorl %r12d, %r12d
xorl %edi, %edi
callq 0x26cd0
movq %rax, %r14
callq 0x26420
xorl %eax, %r14d
movl %r14d, %edi
callq 0x26960
leaq 0x8(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x26300
movl 0x8(%r14), %r15d
xorl (%r14), %r15d
callq 0x26420
xorl %eax, %r15d
movl %r15d, %edi
callq 0x2a093
movl %ebp, %edi
movq %rbx, %rsi
callq 0x3077c
movl %eax, 0xc8d79(%rip)     # 0xf9944
callq 0x2ce58
movq (%rbx), %rdi
callq 0x39be8
movq %rax, 0xc8cd9(%rip)     # 0xf98b8
movslq %ebp, %r14
leaq 0x8(,%r14,8), %rdi
callq 0x327b9
movq %rax, 0xc8cca(%rip)     # 0xf98c0
andq $0x0, (%rax,%r14,8)
testl %r14d, %r14d
movl $0x0, %r15d
cmovgl %ebp, %r15d
cmpq %r12, %r15
je 0x30c26
movq (%rbx,%r12,8), %rdi
callq 0x32933
movq 0xc8ca3(%rip), %rcx     # 0xf98c0
movq %rax, (%rcx,%r12,8)
incq %r12
jmp 0x30c08
cmpl $0x0, 0xc8d17(%rip)     # 0xf9944
je 0x30c39
callq 0x6a442
callq 0x6a454
movq (%rbx), %rdi
leaq 0x803f8(%rip), %rsi     # 0xb103b
callq 0x266b0
testq %rax, %rax
je 0x30c57
movl %ebp, %edi
movq %rbx, %rsi
callq 0x73837
cmpl $0x2, %ebp
jl 0x30d00
callq 0x3114c
movq %rax, %r15
movq 0x8(%rbx), %rdi
movb (%rdi), %r12b
cmpb $0x2d, %r12b
jne 0x30c85
cmpb $0x76, 0x1(%rdi)
jne 0x30c85
cmpb $0x0, 0x2(%rdi)
je 0x30f80
leaq 0x803bf(%rip), %rsi     # 0xb104b
movq %rdi, (%rsp)
callq 0x268f0
testl %eax, %eax
movq (%rsp), %rdi
je 0x30f80
leaq 0x803ad(%rip), %rsi     # 0xb1055
callq 0x268f0
testl %eax, %eax
movq (%rsp), %rdi
je 0x30f85
cmpb $0x2d, %r12b
jne 0x30ccf
cmpb $0x68, 0x1(%rdi)
jne 0x30ccf
cmpb $0x0, 0x2(%rdi)
je 0x30f85
leaq 0x80386(%rip), %rsi     # 0xb105c
callq 0x268f0
testl %eax, %eax
je 0x30f8a
cmpb $0x2d, %r12b
movq (%rsp), %rdi
jne 0x30d32
cmpb $0x2d, 0x1(%rdi)
jne 0x30d32
pushq $0x1
popq %rbp
movq $0x0, (%rsp)
jmp 0x30d68
movq (%rbx), %rdx
cmpl $0x0, 0xc8c3a(%rip)     # 0xf9944
leaq 0x7e2a7(%rip), %rax     # 0xaefb8
leaq 0x8cafa(%rip), %rcx     # 0xbd812
cmoveq %rax, %rcx
leaq 0x80421(%rip), %rsi     # 0xb1144
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
jmp 0x30e3e
callq 0x39be8
movq %rax, 0xc8b72(%rip)     # 0xf98b0
movq 0xc8b7b(%rip), %rax     # 0xf98c0
movq 0x8(%rax), %rdi
callq 0x328f9
movq 0xc8b5b(%rip), %rdi     # 0xf98b0
callq 0x32933
movq 0xc8b5f(%rip), %rcx     # 0xf98c0
movq %rax, 0x8(%rcx)
pushq $0x2
popq %rbp
negq %r14
leaq 0x80360(%rip), %r12     # 0xb10d2
movslq %ebp, %rbp
incq %rbp
leaq (%r14,%rbp), %rax
cmpq $0x1, %rax
je 0x30e0a
movq -0x8(%rbx,%rbp,8), %r13
cmpb $0x2d, (%r13)
jne 0x30ddd
cmpb $0x2d, 0x1(%r13)
jne 0x30ddd
movq %r13, %rdi
movq %r12, %rsi
callq 0x268f0
testl %eax, %eax
je 0x30d75
movq %r15, %rdi
callq 0x2b91b
testq %rax, %rax
je 0x30dcc
movq %r15, %rdi
leaq 0x7fffa(%rip), %rsi     # 0xb0db9
callq 0x317b7
movq %rax, %r15
movq -0x8(%rbx,%rbp,8), %r13
addq $0x2, %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x317b7
jmp 0x30df3
movq %r13, %rdi
callq 0x26500
movq %r15, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x321f1
movq %rax, %rdi
leaq 0x85254(%rip), %rsi     # 0xb6051
callq 0x317b7
movq %rax, %r15
jmp 0x30d72
movq (%rsp), %r14
testq %r14, %r14
je 0x30e26
cmpl $0x0, 0xc8b2a(%rip)     # 0xf9944
je 0x30e26
cmpb $0x2d, (%r14)
je 0x30fe0
callq 0x4de32
movq %r14, %rdi
movq %r15, %rsi
callq 0x4f48b
movq %r15, %rdi
callq 0x311c8
movl 0xc907c(%rip), %edi     # 0xf9ec0
callq 0x30af3
movl %eax, 0xc906d(%rip)     # 0xf9ebc
cmpl $0x0, 0xc906e(%rip)     # 0xf9ec4
setne %cl
testl %eax, %eax
sete %bpl
andb %cl, %bpl
cmpb $0x1, %bpl
jne 0x30e6d
callq 0x30417
callq 0x2da4f
cmpq $0x0, 0xc8a8e(%rip)     # 0xf9908
setne %al
orb %al, %bpl
cmpb $0x1, %bpl
jne 0x30e8b
callq 0x303bd
movq (%rbx), %rdi
callq 0x308b2
callq 0x305f4
callq 0x2d78d
cmpl $0x0, 0xc8aa0(%rip)     # 0xf9944
je 0x30ead
callq 0x6a557
jmp 0x30f20
leaq 0x80307(%rip), %rsi     # 0xb11bb
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
callq 0x30385
callq 0x307d6
cmpl $0x0, 0xc9375(%rip)     # 0xfa244
je 0x30edf
callq 0x5f4b9
cmpl $-0x1, %eax
je 0x30ffe
cmpl $0x0, 0xc8b3e(%rip)     # 0xf9a24
jle 0x30eff
movl 0xc8a5a(%rip), %edx     # 0xf9948
leaq 0x8033a(%rip), %rsi     # 0xb122f
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x2b699
cmpl $0x0, 0xc8b22(%rip)     # 0xf9a28
jle 0x30f20
movq 0xc8ac9(%rip), %rdx     # 0xf99d8
leaq 0x80352(%rip), %rsi     # 0xb1268
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x2b699
movq 0xc9289(%rip), %rdx     # 0xfa1b0
leaq -0x1(%rdx), %rax
cmpq $0xffffe, %rax          # imm = 0xFFFFE
ja 0x30f44
leaq 0x80362(%rip), %rsi     # 0xb129c
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
movq 0xc899d(%rip), %rdi     # 0xf98e8
leaq -0x479e(%rip), %rsi     # 0x2c7b4
callq 0x29179
movq 0xc898a(%rip), %rdi     # 0xf98e8
callq 0x2913a
movq 0xc897e(%rip), %rdi     # 0xf98e8
callq 0x28a9b
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x30473
callq 0x304c8
cmpl $0x3, %ebp
jne 0x30faa
movq 0x10(%rbx), %rdi
callq 0x26760
movslq %eax, %rdi
pushq $0x32
popq %rsi
callq 0x67ab3
xorl %edi, %edi
callq 0x262c0
movq 0xc4017(%rip), %r14     # 0xf4fc8
movq (%r14), %rcx
leaq 0x800af(%rip), %rdi     # 0xb106a
pushq $0x3a
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x26b10
movq (%r14), %rcx
leaq 0x800d2(%rip), %rdi     # 0xb10a5
pushq $0x2c
popq %rsi
movq %rbx, %rdx
callq 0x26b10
jmp 0x3100f
leaq 0x800f7(%rip), %rsi     # 0xb10de
pushq $0x3
popq %rbx
movl %ebx, %edi
xorl %eax, %eax
callq 0x2b699
leaq 0x8010c(%rip), %rsi     # 0xb1106
movl %ebx, %edi
jmp 0x31008
leaq 0x801db(%rip), %rsi     # 0xb11e0
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
pushq $0x1
popq %rdi
callq 0x262c0
nop