// File: /workspace/github_c_makefile_star2_O2/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 0x289e8
leaq 0x35b89(%rip), %rsi     # 0x4eb4d
pushq $0x3
popq %rdi
callq 0x12660
callq 0x1acff
leaq -0x2bb(%rip), %rdi      # 0x18d1d
callq 0x1ad07
xorl %r12d, %r12d
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 0x14588
callq 0x16b9f
movq (%rbx), %rdi
callq 0x1f7b5
movq %rax, 0x51064(%rip)     # 0x6a098
movslq %ebp, %r14
leaq 0x8(,%r14,8), %rdi
callq 0x1ab29
movq %rax, 0x51055(%rip)     # 0x6a0a0
andq $0x0, (%rax,%r14,8)
testl %r14d, %r14d
movl $0x0, %r14d
cmovgl %ebp, %r14d
cmpq %r12, %r14
je 0x1907b
movq (%rbx,%r12,8), %rdi
callq 0x1acc3
movq 0x5102e(%rip), %rcx     # 0x6a0a0
movq %rax, (%rcx,%r12,8)
incq %r12
jmp 0x1905d
cmpl $0x2, %ebp
jl 0x19129
callq 0x194cc
movq %rax, %r15
movq 0x8(%rbx), %r12
movb (%r12), %r14b
cmpb $0x2d, %r14b
jne 0x190ae
cmpb $0x76, 0x1(%r12)
jne 0x190ae
cmpb $0x0, 0x2(%r12)
je 0x19330
leaq 0x34e5d(%rip), %rsi     # 0x4df12
movq %r12, %rdi
callq 0x12490
testl %eax, %eax
je 0x19330
leaq 0x34e50(%rip), %rsi     # 0x4df1c
movq %r12, %rdi
callq 0x12490
testl %eax, %eax
je 0x19335
cmpb $0x2d, %r14b
jne 0x190f6
cmpb $0x68, 0x1(%r12)
jne 0x190f6
cmpb $0x0, 0x2(%r12)
je 0x19335
leaq 0x34e26(%rip), %rsi     # 0x4df23
movq %r12, %rdi
callq 0x12490
testl %eax, %eax
je 0x1933a
cmpb $0x2d, %r14b
jne 0x19142
cmpb $0x2d, 0x1(%r12)
jne 0x19142
pushq $0x1
popq %r12
movq $0x0, (%rsp)
jmp 0x19180
movq (%rbx), %rdx
leaq 0x34e67(%rip), %rsi     # 0x4df9a
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x15b9e
jmp 0x19210
movq %r12, (%rsp)
movq %r12, %rdi
callq 0x1f7b5
movq %rax, 0x50f3b(%rip)     # 0x6a090
movq 0x50f44(%rip), %rax     # 0x6a0a0
movq 0x8(%rax), %rdi
callq 0x1ac81
movq 0x50f24(%rip), %rdi     # 0x6a090
callq 0x1acc3
movq 0x50f28(%rip), %rcx     # 0x6a0a0
movq %rax, 0x8(%rcx)
pushq $0x2
popq %r12
movl %ebp, %r14d
leaq 0x3649c(%rip), %r13     # 0x4f626
cmpq %r12, %r14
je 0x191fc
movq (%rbx,%r12,8), %rbp
cmpb $0x2d, (%rbp)
jne 0x191d3
cmpb $0x2d, 0x1(%rbp)
jne 0x191d3
movq %r15, %rdi
callq 0x15e43
testq %rax, %rax
je 0x191c2
movq %r15, %rdi
leaq 0x34b42(%rip), %rsi     # 0x4dcf8
callq 0x19b37
movq %rax, %r15
movq (%rbx,%r12,8), %rbp
addq $0x2, %rbp
movq %r15, %rdi
movq %rbp, %rsi
callq 0x19b37
jmp 0x191e9
movq %rbp, %rdi
callq 0x12250
movq %r15, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x1a571
movq %rax, %rdi
movq %r13, %rsi
callq 0x19b37
movq %rax, %r15
incq %r12
jmp 0x1918a
movq (%rsp), %rdi
movq %r15, %rsi
callq 0x2117b
movq %r15, %rdi
callq 0x19548
movl 0x51426(%rip), %edi     # 0x6a63c
callq 0x18f58
movl %eax, 0x51417(%rip)     # 0x6a638
cmpl $0x0, 0x51418(%rip)     # 0x6a640
setne %cl
testl %eax, %eax
sete %bpl
andb %cl, %bpl
cmpb $0x1, %bpl
jne 0x1923f
callq 0x189a9
callq 0x17475
cmpq $0x0, 0x50e8c(%rip)     # 0x6a0d8
setne %al
orb %al, %bpl
cmpb $0x1, %bpl
jne 0x1925d
callq 0x1896a
movq (%rbx), %rdi
callq 0x18d52
callq 0x18b5c
leaq 0x34da4(%rip), %rsi     # 0x4e015
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x15b9e
callq 0x1894c
callq 0x1722b
callq 0x18caa
cmpl $0x0, 0x50f8b(%rip)     # 0x6a21c
jle 0x192aa
movl 0x50ea3(%rip), %edx     # 0x6a13c
leaq 0x34d9a(%rip), %rsi     # 0x4e03a
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x15b9e
cmpl $0x0, 0x50f6f(%rip)     # 0x6a220
jle 0x192cb
movq 0x50f16(%rip), %rdx     # 0x6a1d0
leaq 0x34db2(%rip), %rsi     # 0x4e073
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x15b9e
movq 0x513c6(%rip), %rdx     # 0x6a698
leaq -0x1(%rdx), %rax
cmpq $0xffffe, %rax          # imm = 0xFFFFE
ja 0x192ef
leaq 0x34dc2(%rip), %rsi     # 0x4e0a7
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x15b9e
movq 0x50dca(%rip), %rdi     # 0x6a0c0
leaq -0x2c65(%rip), %rsi     # 0x16698
callq 0x13709
callq 0x16337
movq 0x50db2(%rip), %rdi     # 0x6a0c0
callq 0x136ca
movq 0x50da6(%rip), %rdi     # 0x6a0c0
callq 0x1301f
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x18a05
callq 0x18a5a
cmpl $0x3, %ebp
jne 0x1935a
movq 0x10(%rbx), %rdi
callq 0x12820
movslq %eax, %rdi
pushq $0x32
popq %rsi
callq 0x2894c
xorl %edi, %edi
callq 0x12860
movq 0x4fc8f(%rip), %r14     # 0x68ff0
movq (%r14), %rcx
leaq 0x34bc6(%rip), %rdi     # 0x4df31
pushq $0x3a
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x12880
movq (%r14), %rcx
leaq 0x34be9(%rip), %rdi     # 0x4df6c
pushq $0x2d
popq %rsi
movq %rbx, %rdx
callq 0x12880
pushq $0x1
popq %rdi
callq 0x12860
nop