// File: /workspace/github_c_makefile_star2_O1/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 0x2fde0
leaq 0x378e4(%rip), %rsi     # 0x55205
movl $0x3, %edi
callq 0x12670
callq 0x2007d
leaq -0x30c(%rip), %rdi      # 0x1d62b
callq 0x20085
xorl %edi, %edi
callq 0x12550
movq %rax, %r14
callq 0x121f0
xorl %eax, %r14d
movl %r14d, %edi
callq 0x12430
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 0x187a8
callq 0x1b275
movq (%rbx), %rdi
callq 0x257b5
movq %rax, 0x51708(%rip)     # 0x6f098
movslq %ebp, %r14
leaq 0x8(,%r14,8), %rdi
callq 0x1fea5
movq %rax, 0x516f9(%rip)     # 0x6f0a0
movq $0x0, (%rax,%r14,8)
testl %r14d, %r14d
jle 0x1d9d6
movl %ebp, %r14d
xorl %r15d, %r15d
movq (%rbx,%r15,8), %rdi
callq 0x20041
movq 0x516d6(%rip), %rcx     # 0x6f0a0
movq %rax, (%rcx,%r15,8)
incq %r15
cmpq %r15, %r14
jne 0x1d9ba
cmpl $0x2, %ebp
jl 0x1da7d
callq 0x1de3f
movq %rax, %r14
movq 0x8(%rbx), %r15
leaq 0x365b3(%rip), %rsi     # 0x53fa5
movq %r15, %rdi
callq 0x124a0
testl %eax, %eax
je 0x1dcf9
leaq 0x3659f(%rip), %rsi     # 0x53fa8
movq %r15, %rdi
callq 0x124a0
testl %eax, %eax
je 0x1dcf9
movq 0x8(%rbx), %r15
leaq 0x3658e(%rip), %rsi     # 0x53fb2
movq %r15, %rdi
callq 0x124a0
testl %eax, %eax
je 0x1dcfe
leaq 0x3657e(%rip), %rsi     # 0x53fb9
movq %r15, %rdi
callq 0x124a0
testl %eax, %eax
je 0x1dcfe
movq 0x8(%rbx), %r15
leaq 0x36566(%rip), %rsi     # 0x53fbc
movq %r15, %rdi
callq 0x124a0
testl %eax, %eax
je 0x1dd03
cmpb $0x2d, (%r15)
jne 0x1da98
cmpb $0x2d, 0x1(%r15)
jne 0x1da98
movl $0x1, %eax
xorl %r15d, %r15d
jmp 0x1dad3
movq (%rbx), %rdx
leaq 0x365ac(%rip), %rsi     # 0x54033
movl $0x3, %edi
xorl %eax, %eax
callq 0x19fb1
jmp 0x1dba9
movq %r15, %rdi
callq 0x257b5
movq %rax, 0x515e9(%rip)     # 0x6f090
movq 0x515f2(%rip), %rax     # 0x6f0a0
movq 0x8(%rax), %rdi
callq 0x1ffff
movq 0x515d2(%rip), %rdi     # 0x6f090
callq 0x20041
movq 0x515d6(%rip), %rcx     # 0x6f0a0
movq %rax, 0x8(%rcx)
movl $0x2, %eax
movq %r15, (%rsp)
cmpl %ebp, %eax
je 0x1db95
movl %eax, %r12d
movl %ebp, %r15d
leaq 0x382ee(%rip), %r13     # 0x55dda
movq (%rbx,%r12,8), %rbp
cmpb $0x2d, (%rbp)
jne 0x1db20
cmpb $0x2d, 0x1(%rbp)
jne 0x1db20
movzbl -0x1(%r14), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x1db52
leaq 0x34902(%rip), %rdx     # 0x52414
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrl $0x3, %eax
jmp 0x1db54
movq %rbp, %rdi
callq 0x12250
movq %r14, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x1f7c8
jmp 0x1db7b
movq -0x11(%r14), %rax
jmp 0x1db54
movzwl -0x5(%r14), %eax
jmp 0x1db54
movl -0x9(%r14), %eax
jmp 0x1db54
movzbl -0x3(%r14), %eax
jmp 0x1db54
xorl %eax, %eax
testq %rax, %rax
je 0x1db6b
movq %r14, %rdi
leaq 0x36225(%rip), %rsi     # 0x53d88
callq 0x1e73d
movq %rax, %r14
movq (%rbx,%r12,8), %rsi
addq $0x2, %rsi
movq %r14, %rdi
callq 0x1e73d
movq %rax, %rdi
movq %r13, %rsi
callq 0x1e73d
movq %rax, %r14
incq %r12
cmpq %r12, %r15
jne 0x1daec
movq (%rsp), %rdi
movq %r14, %rsi
callq 0x27649
movq %r14, %rdi
callq 0x1ded3
movl 0x51a8d(%rip), %edi     # 0x6f63c
callq 0x1d8b5
movl %eax, 0x51a7e(%rip)     # 0x6f638
cmpl $0x0, 0x51a7f(%rip)     # 0x6f640
setne %cl
testl %eax, %eax
sete %bpl
andb %cl, %bpl
cmpb $0x1, %bpl
jne 0x1dbd8
callq 0x1d23a
callq 0x1bb8b
cmpq $0x0, 0x514f3(%rip)     # 0x6f0d8
setne %al
orb %al, %bpl
cmpb $0x1, %bpl
jne 0x1dbf6
callq 0x1d1fb
movq (%rbx), %rsi
cmpl $0x0, 0x515c8(%rip)     # 0x6f1c8
je 0x1dc0b
movq 0x5153f(%rip), %rdx     # 0x6f148
jmp 0x1dc12
leaq 0x352cb(%rip), %rdx     # 0x52edd
movl 0x51524(%rip), %ecx     # 0x6f13c
leaq 0x3623c(%rip), %rdi     # 0x53e5b
xorl %eax, %eax
callq 0x2ffb4
callq 0x1d418
leaq 0x3647c(%rip), %rsi     # 0x540ae
movl $0x3, %edi
xorl %eax, %eax
callq 0x19fb1
callq 0x1d1db
callq 0x1b8f6
callq 0x1d572
cmpl $0x0, 0x515c8(%rip)     # 0x6f21c
jle 0x1dc6f
movl 0x514e0(%rip), %edx     # 0x6f13c
leaq 0x36470(%rip), %rsi     # 0x540d3
movl $0x2, %edi
xorl %eax, %eax
callq 0x19fb1
cmpl $0x0, 0x515aa(%rip)     # 0x6f220
jle 0x1dc92
movq 0x51551(%rip), %rdx     # 0x6f1d0
leaq 0x36486(%rip), %rsi     # 0x5410c
movl $0x2, %edi
xorl %eax, %eax
callq 0x19fb1
movq 0x519ff(%rip), %rdx     # 0x6f698
leaq -0x1(%rdx), %rax
cmpq $0xffffe, %rax          # imm = 0xFFFFE
ja 0x1dcb8
leaq 0x36494(%rip), %rsi     # 0x54140
movl $0x3, %edi
xorl %eax, %eax
callq 0x19fb1
movq 0x51401(%rip), %rdi     # 0x6f0c0
leaq -0x2f61(%rip), %rsi     # 0x1ad65
callq 0x177c6
callq 0x1a9f0
movq 0x513e9(%rip), %rdi     # 0x6f0c0
callq 0x17790
movq 0x513dd(%rip), %rdi     # 0x6f0c0
callq 0x1702a
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1d29c
callq 0x1d2f3
cmpl $0x3, %ebp
jne 0x1dd25
movq 0x10(%rbx), %rdi
callq 0x12830
movslq %eax, %rdi
movl $0x32, %esi
callq 0x2fd3e
xorl %edi, %edi
callq 0x12870
callq 0x12a10
nop