// File: /workspace/github_c_makefile_star2_O3/erikdubbelboer[P]discnt/src/server.c
// Function: main
int main(int argc, char **argv) {
    struct timeval tv;
    int j;

    /* 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(serverOutOfMemoryHandler);
    srand(time(NULL)^getpid());
    gettimeofday(&tv,NULL);
    dictSetHashFunctionSeed(tv.tv_sec^tv.tv_usec^getpid());
    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]);

    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: ./discnt-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 (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++;
        }
        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/discnt.conf", argv[0]);
    }

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

    initServer();
    if (background || server.pidfile) createPidFile();
    serverSetProcTitle(argv[0]);
    discntAsciiArt();

    /* Things not needed when running in Sentinel mode. */
    serverLog(LL_WARNING,"Server started, Discnt version " DISCNT_VERSION);
#ifdef __linux__
    linuxOvercommitMemoryWarning();
#endif
    checkTcpBacklogSettings();
    loadDataFromDisk();
    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);

    /* 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);
    /* Make sure to do a cron run before 1st client is served, so that we
     * can do periodic tasks there that we can assume to always be executed
     * at least once before the server starts serving queries. */
    serverCron(NULL,0,NULL);
    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 0x2f814
leaq 0x37bc0(%rip), %rsi     # 0x5521d
movl $0x3, %edi
callq 0x12660
callq 0x1fd95
leaq -0x2c7(%rip), %rdi      # 0x1d3ac
callq 0x1fd9d
xorl %edi, %edi
callq 0x12540
movq %rax, %r14
callq 0x121f0
xorl %eax, %r14d
movl %r14d, %edi
callq 0x12420
leaq 0x8(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x12340
movl 0x8(%r14), %r15d
xorl (%r14), %r15d
callq 0x121f0
xorl %eax, %r15d
movl %r15d, %edi
callq 0x18408
callq 0x1aeec
movq (%rbx), %rdi
callq 0x253ea
movq %rax, 0x519cc(%rip)     # 0x6f098
movslq %ebp, %r14
leaq 0x8(,%r14,8), %rdi
callq 0x1fbbd
movq %rax, 0x519bd(%rip)     # 0x6f0a0
movq $0x0, (%rax,%r14,8)
testl %r14d, %r14d
jle 0x1d717
movl %ebp, %r12d
xorl %r14d, %r14d
movq (%rbx,%r14,8), %rdi
callq 0x1fd59
movq 0x5199a(%rip), %rcx     # 0x6f0a0
movq %rax, (%rcx,%r14,8)
incq %r14
cmpq %r14, %r12
jne 0x1d6f6
cmpl $0x1, %ebp
jne 0x1d732
movq (%rbx), %rdx
leaq 0x36959(%rip), %rsi     # 0x5407a
movl $0x3, %edi
xorl %eax, %eax
callq 0x19c06
jmp 0x1d8ec
callq 0x1db82
movq %rax, %r15
movq 0x8(%rbx), %r13
movb (%r13), %r14b
cmpb $0x2d, %r14b
jne 0x1d75a
cmpb $0x76, 0x1(%r13)
jne 0x1d75a
cmpb $0x0, 0x2(%r13)
je 0x1da3c
leaq 0x36891(%rip), %rsi     # 0x53ff2
movq %r13, %rdi
callq 0x12490
testl %eax, %eax
je 0x1da3c
leaq 0x36884(%rip), %rsi     # 0x53ffc
movq %r13, %rdi
callq 0x12490
testl %eax, %eax
je 0x1da41
cmpb $0x2d, %r14b
jne 0x1d7c8
cmpb $0x68, 0x1(%r13)
jne 0x1d7a0
cmpb $0x0, 0x2(%r13)
je 0x1da41
leaq 0x3685c(%rip), %rsi     # 0x54003
movq %r13, %rdi
callq 0x12490
testl %eax, %eax
je 0x1da46
cmpb $0x2d, 0x1(%r13)
jne 0x1d7df
movl $0x1, %eax
xorl %r13d, %r13d
jmp 0x1d81a
leaq 0x36834(%rip), %rsi     # 0x54003
movq %r13, %rdi
callq 0x12490
testl %eax, %eax
je 0x1da46
movq %r13, %rdi
callq 0x253ea
movq %rax, 0x518a2(%rip)     # 0x6f090
movq 0x518ab(%rip), %rax     # 0x6f0a0
movq 0x8(%rax), %rdi
callq 0x1fd17
movq 0x5188b(%rip), %rdi     # 0x6f090
callq 0x1fd59
movq 0x5188f(%rip), %rcx     # 0x6f0a0
movq %rax, 0x8(%rcx)
movl $0x2, %eax
movq %r13, (%rsp)
cmpl %ebp, %eax
je 0x1d8d8
movl %eax, %r14d
leaq 0x385a6(%rip), %r13     # 0x55dd6
movq (%rbx,%r14,8), %rbp
cmpb $0x2d, (%rbp)
jne 0x1d864
cmpb $0x2d, 0x1(%rbp)
jne 0x1d864
movzbl -0x1(%r15), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x1d8af
leaq 0x34c0a(%rip), %rdx     # 0x52460
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrl $0x3, %eax
jmp 0x1d894
movq %rbp, %rdi
callq 0x12250
movq %r15, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x1f52f
jmp 0x1d8be
movq -0x11(%r15), %rax
jmp 0x1d894
movzwl -0x5(%r15), %eax
jmp 0x1d894
movl -0x9(%r15), %eax
jmp 0x1d894
movzbl -0x3(%r15), %eax
testq %rax, %rax
je 0x1d8af
movq %r15, %rdi
leaq 0x36535(%rip), %rsi     # 0x53dd8
callq 0x1e495
movq %rax, %r15
movq (%rbx,%r14,8), %rbp
addq $0x2, %rbp
movq %r15, %rdi
movq %rbp, %rsi
callq 0x1e495
movq %rax, %rdi
movq %r13, %rsi
callq 0x1e495
movq %rax, %r15
incq %r14
cmpq %r14, %r12
jne 0x1d830
movq (%rsp), %rdi
movq %r15, %rsi
callq 0x2711d
movq %r15, %rdi
callq 0x1dc25
movl 0x51d4a(%rip), %edi     # 0x6f63c
callq 0x1d5f1
movl %eax, 0x51d3b(%rip)     # 0x6f638
cmpl $0x0, 0x51d3c(%rip)     # 0x6f640
setne %cl
testl %eax, %eax
sete %bpl
andb %cl, %bpl
cmpb $0x1, %bpl
jne 0x1d91b
callq 0x1cfbb
callq 0x1b836
cmpq $0x0, 0x517b0(%rip)     # 0x6f0d8
setne %al
orb %al, %bpl
cmpb $0x1, %bpl
jne 0x1d939
callq 0x1cf7c
movq (%rbx), %rsi
cmpl $0x0, 0x51885(%rip)     # 0x6f1c8
je 0x1d94e
movq 0x517fc(%rip), %rdx     # 0x6f148
jmp 0x1d955
leaq 0x355d8(%rip), %rdx     # 0x52f2d
movl 0x517e1(%rip), %ecx     # 0x6f13c
leaq 0x36549(%rip), %rdi     # 0x53eab
xorl %eax, %eax
callq 0x2fa07
callq 0x1d199
leaq 0x36780(%rip), %rsi     # 0x540f5
movl $0x3, %edi
xorl %eax, %eax
callq 0x19c06
callq 0x1cf5c
callq 0x1b59e
callq 0x1d2f3
cmpl $0x0, 0x51885(%rip)     # 0x6f21c
jle 0x1d9b2
movl 0x5179d(%rip), %edx     # 0x6f13c
leaq 0x36774(%rip), %rsi     # 0x5411a
movl $0x2, %edi
xorl %eax, %eax
callq 0x19c06
cmpl $0x0, 0x51867(%rip)     # 0x6f220
jle 0x1d9d5
movq 0x5180e(%rip), %rdx     # 0x6f1d0
leaq 0x3678a(%rip), %rsi     # 0x54153
movl $0x2, %edi
xorl %eax, %eax
callq 0x19c06
movq 0x51cbc(%rip), %rdx     # 0x6f698
leaq -0x1(%rdx), %rax
cmpq $0xffffe, %rax          # imm = 0xFFFFE
ja 0x1d9fb
leaq 0x36798(%rip), %rsi     # 0x54187
movl $0x3, %edi
xorl %eax, %eax
callq 0x19c06
movq 0x516be(%rip), %rdi     # 0x6f0c0
leaq -0x302d(%rip), %rsi     # 0x1a9dc
callq 0x17460
callq 0x1a656
movq 0x516a6(%rip), %rdi     # 0x6f0c0
callq 0x1742a
movq 0x5169a(%rip), %rdi     # 0x6f0c0
callq 0x16cb5
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1d01d
callq 0x1d074
cmpl $0x3, %ebp
jne 0x1da68
movq 0x10(%rbx), %rdi
callq 0x12820
movslq %eax, %rdi
movl $0x32, %esi
callq 0x2f772
xorl %edi, %edi
callq 0x12860
callq 0x12a00
nopl (%rax)