// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/server.c
// Function: initServer
void initServer(void) {
    int j;

    signal(SIGHUP, SIG_IGN);
    signal(SIGPIPE, SIG_IGN);
    setupSignalHandlers();

    if (server.syslog_enabled) {
        openlog(server.syslog_ident, LOG_PID | LOG_NDELAY | LOG_NOWAIT,
            server.syslog_facility);
    }

    server.pid = getpid();
    server.current_client = NULL;
    server.clients = listCreate();
    server.clients_to_close = listCreate();
    server.slaves = listCreate();
    server.monitors = listCreate();
    server.clients_pending_write = listCreate();
    server.slaveseldb = -1; /* Force to emit the first SELECT command. */
    server.unblocked_clients = listCreate();
    server.ready_keys = listCreate();
    server.clients_waiting_acks = listCreate();
    server.get_ack_from_slaves = 0;
    server.clients_paused = 0;
    server.system_memory_size = zmalloc_get_memory_size();

    createSharedObjects();
    adjustOpenFilesLimit();
    server.el = aeCreateEventLoop(server.maxclients+CONFIG_FDSET_INCR);
    server.db = zmalloc(sizeof(redisDb)*server.dbnum);

    /* Open the TCP listening socket for the user commands. */
    if (server.port != 0 &&
        listenToPort(server.port,server.ipfd,&server.ipfd_count) == C_ERR)
        exit(1);

    /* Open the listening Unix domain socket. */
    if (server.unixsocket != NULL) {
        unlink(server.unixsocket); /* don't care if this fails */
        server.sofd = anetUnixServer(server.neterr,server.unixsocket,
            server.unixsocketperm, server.tcp_backlog);
        if (server.sofd == ANET_ERR) {
            serverLog(LL_WARNING, "Opening Unix socket: %s", server.neterr);
            exit(1);
        }
        anetNonBlock(NULL,server.sofd);
    }

    /* Abort if there are no listening sockets at all. */
    if (server.ipfd_count == 0 && server.sofd < 0) {
        serverLog(LL_WARNING, "Configured to not listen anywhere, exiting.");
        exit(1);
    }

    /* Create the Redis databases, and initialize other internal state. */
    for (j = 0; j < server.dbnum; j++) {
        server.db[j].dict = dictCreate(&dbDictType,NULL);
        server.db[j].expires = dictCreate(&keyptrDictType,NULL);
        server.db[j].blocking_keys = dictCreate(&keylistDictType,NULL);
        server.db[j].ready_keys = dictCreate(&setDictType,NULL);
        server.db[j].watched_keys = dictCreate(&keylistDictType,NULL);
        server.db[j].eviction_pool = evictionPoolAlloc();
        server.db[j].id = j;
        server.db[j].avg_ttl = 0;
    }
    server.pubsub_channels = dictCreate(&keylistDictType,NULL);
    server.pubsub_patterns = listCreate();
    listSetFreeMethod(server.pubsub_patterns,freePubsubPattern);
    listSetMatchMethod(server.pubsub_patterns,listMatchPubsubPattern);
    server.cronloops = 0;
    server.rdb_child_pid = -1;
    server.aof_child_pid = -1;
    server.rdb_child_type = RDB_CHILD_TYPE_NONE;
    server.rdb_bgsave_scheduled = 0;
    aofRewriteBufferReset();
    server.aof_buf = sdsempty();
    server.lastsave = time(NULL); /* At startup we consider the DB saved. */
    server.lastbgsave_try = 0;    /* At startup we never tried to BGSAVE. */
    server.rdb_save_time_last = -1;
    server.rdb_save_time_start = -1;
    server.dirty = 0;
    resetServerStats();
    /* A few stats we don't want to reset: server startup time, and peak mem. */
    server.stat_starttime = time(NULL);
    server.stat_peak_memory = 0;
    server.resident_set_size = 0;
    server.lastbgsave_status = C_OK;
    server.aof_last_write_status = C_OK;
    server.aof_last_write_errno = 0;
    server.repl_good_slaves_count = 0;
    updateCachedTime();

#ifdef AOF_NO_COW
    pthread_spin_init(&(server.aof_no_cow.lock), PTHREAD_PROCESS_SHARED);
#endif

    /* Create the serverCron() time event, that's our main way to process
     * background operations. */
    if(aeCreateTimeEvent(server.el, 1, serverCron, NULL, NULL) == AE_ERR) {
        serverPanic("Can't create the serverCron time event.");
        exit(1);
    }

    /* Create an event handler for accepting new connections in TCP and Unix
     * domain sockets. */
    for (j = 0; j < server.ipfd_count; j++) {
        if (aeCreateFileEvent(server.el, server.ipfd[j], AE_READABLE,
            acceptTcpHandler,NULL) == AE_ERR)
            {
                serverPanic(
                    "Unrecoverable error creating server.ipfd file event.");
            }
    }
    if (server.sofd > 0 && aeCreateFileEvent(server.el,server.sofd,AE_READABLE,
        acceptUnixHandler,NULL) == AE_ERR) serverPanic("Unrecoverable error creating server.sofd file event.");

    /* Open the AOF file if needed. */
    if (server.aof_state == AOF_ON) {
        server.aof_fd = open(server.aof_filename,
                               O_WRONLY|O_APPEND|O_CREAT,0644);
        if (server.aof_fd == -1) {
            serverLog(LL_WARNING, "Can't open the append-only file: %s",
                strerror(errno));
            exit(1);
        }
    }

    /* 32 bit instances are limited to 4GB of address space, so if there is
     * no explicit limit in the user provided configuration we set a limit
     * at 3 GB using maxmemory with 'noeviction' policy'. This avoids
     * useless crashes of the Redis instance for out of memory. */
    if (server.arch_bits == 32 && server.maxmemory == 0) {
        serverLog(LL_WARNING,"Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.");
        server.maxmemory = 3072LL*(1024*1024); /* 3 GB */
        server.maxmemory_policy = MAXMEMORY_NO_EVICTION;
    }

    if (server.cluster_enabled) clusterInit();
    replicationScriptCacheInit();
    scriptingInit(1);
    slowlogInit();
    latencyMonitorInit();
    bioInit();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl $0x1, %esi
movl $0x1, %edi
callq 0x267e0
movl $0x1, %esi
movl $0xd, %edi
callq 0x267e0
callq 0x35bf9
cmpl $0x0, 0xd18fe(%rip)     # 0x106ff0
je 0x3570b
movq 0xd18fd(%rip), %rdi     # 0x106ff8
movl 0xd18ff(%rip), %edx     # 0x107000
movl $0x19, %esi
callq 0x262b0
callq 0x26430
movl %eax, 0xd1142(%rip)     # 0x106858
movq $0x0, 0xd1327(%rip) # 0x106a48
callq 0x2e33c
movq %rax, 0xd12f3(%rip)     # 0x106a20
callq 0x2e33c
movq %rax, 0xd12ef(%rip)     # 0x106a28
callq 0x2e33c
movq %rax, 0xd12f3(%rip)     # 0x106a38
callq 0x2e33c
movq %rax, 0xd12ef(%rip)     # 0x106a40
callq 0x2e33c
movq %rax, 0xd12d3(%rip)     # 0x106a30
movl $0xffffffff, 0xd189d(%rip) # imm = 0xFFFFFFFF
callq 0x2e33c
movq %rax, 0xd19f5(%rip)     # 0x107168
callq 0x2e33c
movq %rax, 0xd19f1(%rip)     # 0x107170
callq 0x2e33c
movq %rax, 0xd19b5(%rip)     # 0x107140
xorl %eax, %eax
movl %eax, 0xd19b5(%rip)     # 0x107148
movl %eax, 0xd12b7(%rip)     # 0x106a50
callq 0x3b688
movq %rax, 0xd1aeb(%rip)     # 0x107290
callq 0x344a4
callq 0x3522d
movl 0xd1997(%rip), %edi     # 0x10714c
subl $-0x80, %edi
callq 0x2fcd0
movq %rax, 0xd10d4(%rip)     # 0x106898
movslq 0xd168d(%rip), %rdi     # 0x106e58
shlq $0x6, %rdi
callq 0x3b29d
movq %rax, 0xd10a5(%rip)     # 0x106880
movl 0xd1117(%rip), %edi     # 0x1068f8
testl %edi, %edi
je 0x35801
leaq 0xd11a8(%rip), %rsi     # 0x106994
leaq 0xd11e1(%rip), %rdx     # 0x1069d4
callq 0x35412
cmpl $-0x1, %eax
je 0x35bef
movq 0xd1180(%rip), %rdi     # 0x106988
testq %rdi, %rdi
je 0x35849
callq 0x263c0
movq 0xd116f(%rip), %rsi     # 0x106988
movl 0xd1171(%rip), %edx     # 0x106990
movl 0xd10d7(%rip), %ecx     # 0x1068fc
leaq 0xd1234(%rip), %rdi     # 0x106a60
callq 0x31127
movl %eax, 0xd11a1(%rip)     # 0x1069d8
cmpl $-0x1, %eax
je 0x35ba3
xorl %edi, %edi
movl %eax, %esi
callq 0x30779
cmpl $0x0, 0xd1184(%rip)     # 0x1069d4
jne 0x3585f
cmpl $0x0, 0xd117f(%rip)     # 0x1069d8
js 0x35b79
cmpl $0x0, 0xd15f2(%rip)     # 0x106e58
jle 0x35942
xorl %ebp, %ebp
leaq 0xd055b(%rip), %r14     # 0x105dd0
leaq 0xd05e4(%rip), %r15     # 0x105e60
leaq 0xd048d(%rip), %r12     # 0x105d10
xorl %ebx, %ebx
leaq 0xd04e4(%rip), %rdi     # 0x105d70
xorl %esi, %esi
callq 0x31774
movq 0xd0fe6(%rip), %rcx     # 0x106880
movq %rax, (%rcx,%rbp)
movq %r14, %rdi
xorl %esi, %esi
callq 0x31774
movq 0xd0fd1(%rip), %rcx     # 0x106880
movq %rax, 0x8(%rcx,%rbp)
movq %r15, %rdi
xorl %esi, %esi
callq 0x31774
movq 0xd0fbb(%rip), %rcx     # 0x106880
movq %rax, 0x10(%rcx,%rbp)
movq %r12, %rdi
xorl %esi, %esi
callq 0x31774
movq 0xd0fa5(%rip), %rcx     # 0x106880
movq %rax, 0x18(%rcx,%rbp)
movq %r15, %rdi
xorl %esi, %esi
callq 0x31774
movq 0xd0f8f(%rip), %rcx     # 0x106880
movq %rax, 0x20(%rcx,%rbp)
movl $0x100, %edi            # imm = 0x100
callq 0x3b29d
movq %rax, %r13
movl $0x100, %edx            # imm = 0x100
movq %rax, %rdi
xorl %esi, %esi
callq 0x26110
movq 0xd0f67(%rip), %rax     # 0x106880
movq %r13, 0x28(%rax,%rbp)
movl %ebx, 0x30(%rax,%rbp)
movq $0x0, 0x38(%rax,%rbp)
incq %rbx
movslq 0xd1523(%rip), %rax     # 0x106e58
addq $0x40, %rbp
cmpq %rax, %rbx
jl 0x35885
leaq 0xd0517(%rip), %rdi     # 0x105e60
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x31774
movq %rax, 0xd1877(%rip)     # 0x1071d0
callq 0x2e33c
movq %rax, 0xd1873(%rip)     # 0x1071d8
leaq 0x2e050(%rip), %rcx     # 0x639bc
movq %rcx, 0x18(%rax)
leaq 0x2e05b(%rip), %rcx     # 0x639d2
movq %rcx, 0x20(%rax)
movl %ebx, 0xd0f43(%rip)     # 0x1068c4
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0xd15ec(%rip)     # 0x106f78
movl %eax, 0xd1552(%rip)     # 0x106ee4
movq %rbx, 0xd1627(%rip)     # 0x106fc0
callq 0x60910
callq 0x39222
movq %rax, 0xd1546(%rip)     # 0x106ef0
xorl %edi, %edi
callq 0x26ce0
movq %rax, 0xd15e8(%rip)     # 0x106fa0
movq %rbx, 0xd15e9(%rip)     # 0x106fa8
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0xd15e5(%rip)    # 0x106fb0
movq %rbx, 0xd1596(%rip)     # 0x106f68
callq 0x355e8
xorl %edi, %edi
callq 0x26ce0
movq %rax, 0xd11eb(%rip)     # 0x106bd0
movq %rbx, 0xd121c(%rip)     # 0x106c08
movq %rbx, 0xd126d(%rip)     # 0x106c60
movl %ebx, 0xd15cf(%rip)     # 0x106fc8
movq %rbx, 0xd1534(%rip)     # 0x106f34
movl %ebx, 0xd1652(%rip)     # 0x107058
callq 0x33d54
movq 0xd0e86(%rip), %rdi     # 0x106898
leaq -0x1c72(%rip), %rdx     # 0x33da7
movl $0x1, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3008e
cmpq $-0x1, %rax
je 0x35b8e
cmpl $0x0, 0xd0f9b(%rip)     # 0x1069d4
jle 0x35a83
xorl %r14d, %r14d
leaq 0xd0e13(%rip), %r15     # 0x106858
leaq 0xae1a(%rip), %rbx      # 0x40866
movq 0xd0e45(%rip), %rdi     # 0x106898
movl 0x13c(%r15,%r14,4), %esi
movl $0x1, %edx
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x2fee7
cmpl $-0x1, %eax
je 0x35b57
incq %r14
movslq 0xd0f56(%rip), %rax     # 0x1069d4
cmpq %rax, %r14
jl 0x35a4c
movl 0xd0f4f(%rip), %esi     # 0x1069d8
testl %esi, %esi
jle 0x35ab1
movq 0xd0e04(%rip), %rdi     # 0x106898
leaq 0xaf93(%rip), %rcx      # 0x40a2e
movl $0x1, %edx
xorl %r8d, %r8d
callq 0x2fee7
cmpl $-0x1, %eax
je 0x35bb8
cmpl $0x1, 0xd13f8(%rip)     # 0x106eb0
jne 0x35ae1
movq 0xd13f7(%rip), %rdi     # 0x106eb8
movl $0x441, %esi            # imm = 0x441
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0x266a0
movl %eax, 0xd1420(%rip)     # 0x106ef8
cmpl $-0x1, %eax
je 0x35bcd
cmpl $0x20, 0xd0dd8(%rip)    # 0x1068c0
jne 0x35b1d
cmpq $0x0, 0xd165e(%rip)     # 0x107150
jne 0x35b1d
leaq 0x8aa36(%rip), %rsi     # 0xc0531
movl $0x3, %edi
xorl %eax, %eax
callq 0x32ea6
movl $0xc0000000, %eax       # imm = 0xC0000000
movq %rax, 0xd163d(%rip)     # 0x107150
movl $0x5, 0xd163b(%rip)     # 0x107158
cmpl $0x0, 0xd16c0(%rip)     # 0x1071e4
je 0x35b2b
callq 0x69a09
callq 0x4a491
movl $0x1, %edi
callq 0x727fa
callq 0x70e5e
callq 0x825be
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x75d90
leaq 0x8a941(%rip), %rdi     # 0xc049f
leaq 0x8a931(%rip), %rsi     # 0xc0496
movl $0x812, %edx            # imm = 0x812
callq 0x6558d
movl $0x1, %edi
callq 0x263d0
leaq 0x8a8c0(%rip), %rsi     # 0xc0440
movl $0x3, %edi
xorl %eax, %eax
callq 0x32ea6
jmp 0x35bef
leaq 0x8a8d7(%rip), %rdi     # 0xc046c
leaq 0x8a8fa(%rip), %rsi     # 0xc0496
movl $0x807, %edx            # imm = 0x807
jmp 0x35b6a
leaq 0x8a87e(%rip), %rsi     # 0xc0428
leaq 0xd0eaf(%rip), %rdx     # 0x106a60
movl $0x3, %edi
jmp 0x35be8
leaq 0x8a917(%rip), %rdi     # 0xc04d6
leaq 0x8a8d0(%rip), %rsi     # 0xc0496
movl $0x816, %edx            # imm = 0x816
jmp 0x35b6a
callq 0x26890
movl (%rax), %edi
callq 0x26690
leaq 0x8a92d(%rip), %rsi     # 0xc050d
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x32ea6
movl $0x1, %edi
callq 0x262d0