// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/server.c
// Function: serverCron
int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
    int j;
    UNUSED(eventLoop);
    UNUSED(id);
    UNUSED(clientData);

    /* Software watchdog: deliver the SIGALRM that will reach the signal
     * handler if we don't return here fast enough. */
    if (server.watchdog_period) watchdogScheduleSignal(server.watchdog_period);

    /* Update the time cache. */
    updateCachedTime();

    run_with_period(100) {
        trackInstantaneousMetric(STATS_METRIC_COMMAND,server.stat_numcommands);
        trackInstantaneousMetric(STATS_METRIC_NET_INPUT,
                server.stat_net_input_bytes);
        trackInstantaneousMetric(STATS_METRIC_NET_OUTPUT,
                server.stat_net_output_bytes);
    }

    /* We have just LRU_BITS bits per object for LRU information.
     * So we use an (eventually wrapping) LRU clock.
     *
     * Note that even if the counter wraps it's not a big problem,
     * everything will still work but some object will appear younger
     * to Redis. However for this to happen a given object should never be
     * touched for all the time needed to the counter to wrap, which is
     * not likely.
     *
     * Note that you can change the resolution altering the
     * LRU_CLOCK_RESOLUTION define. */
    server.lruclock = getLRUClock();

    /* Record the max memory used since the server was started. */
    if (zmalloc_used_memory() > server.stat_peak_memory)
        server.stat_peak_memory = zmalloc_used_memory();

    /* Sample the RSS here since this is a relatively slow call. */
    server.resident_set_size = zmalloc_get_rss();

    /* We received a SIGTERM, shutting down here in a safe way, as it is
     * not ok doing so inside the signal handler. */
    if (server.shutdown_asap) {
        if (prepareForShutdown(SHUTDOWN_NOFLAGS) == C_OK) exit(0);
        serverLog(LL_WARNING,"SIGTERM received but errors trying to shut down the server, check the logs for more information");
        server.shutdown_asap = 0;
    }

    /* Show some info about non-empty databases */
    run_with_period(5000) {
        for (j = 0; j < server.dbnum; j++) {
            long long size, used, vkeys;

            size = dictSlots(server.db[j].dict);
            used = dictSize(server.db[j].dict);
            vkeys = dictSize(server.db[j].expires);
            if (used || vkeys) {
                serverLog(LL_VERBOSE,"DB %d: %lld keys (%lld volatile) in %lld slots HT.",j,used,vkeys,size);
                /* dictPrintStats(server.dict); */
            }
        }
    }

    /* Show information about connected clients */
    if (!server.sentinel_mode) {
        run_with_period(5000) {
            serverLog(LL_VERBOSE,
                "%lu clients connected (%lu slaves), %zu bytes in use",
                listLength(server.clients)-listLength(server.slaves),
                listLength(server.slaves),
                zmalloc_used_memory());
        }
    }

    /* We need to do a few operations on clients asynchronously. */
    clientsCron();

    /* Handle background operations on Redis databases. */
    databasesCron();

    /* Start a scheduled AOF rewrite if this was requested by the user while
     * a BGSAVE was in progress. */
    if (server.rdb_child_pid == -1 && server.aof_child_pid == -1 &&
        server.aof_rewrite_scheduled)
    {
        rewriteAppendOnlyFileBackground();
    }

    /* Check if a background saving or AOF rewrite in progress terminated. */
    if (server.rdb_child_pid != -1 || server.aof_child_pid != -1 ||
        ldbPendingChildren())
    {
        int statloc;
        pid_t pid;

#ifndef AOF_NO_COW
        if ((pid = wait3(&statloc,WNOHANG,NULL)) != 0)
#else
        if((pid = wait3(&statloc, WNOHANG | __WALL, NULL)) != 0)
#endif
        {
            int exitcode = WEXITSTATUS(statloc);
            int bysignal = 0;

            if (WIFSIGNALED(statloc)) bysignal = WTERMSIG(statloc);

            if (pid == -1) {
                serverLog(LL_WARNING,"wait3() returned an error: %s. "
                    "rdb_child_pid = %d, aof_child_pid = %d",
                    strerror(errno),
                    (int) server.rdb_child_pid,
                    (int) server.aof_child_pid);
            } else if (pid == server.rdb_child_pid) {
                backgroundSaveDoneHandler(exitcode,bysignal);
            } else if (pid == server.aof_child_pid) {
                backgroundRewriteDoneHandler(exitcode,bysignal);
            } else {
                if (!ldbRemoveChild(pid)) {
                    serverLog(LL_WARNING,
                        "Warning, detected child with unmatched pid: %ld",
                        (long)pid);
                }
            }
            updateDictResizePolicy();
        }
    } else {
        /* If there is not a background saving/rewrite in progress check if
         * we have to save/rewrite now */
         for (j = 0; j < server.saveparamslen; j++) {
            struct saveparam *sp = server.saveparams+j;

            /* Save if we reached the given amount of changes,
             * the given amount of seconds, and if the latest bgsave was
             * successful or if, in case of an error, at least
             * CONFIG_BGSAVE_RETRY_DELAY seconds already elapsed. */
            if (server.dirty >= sp->changes &&
                server.unixtime-server.lastsave > sp->seconds &&
                (server.unixtime-server.lastbgsave_try >
                 CONFIG_BGSAVE_RETRY_DELAY ||
                 server.lastbgsave_status == C_OK))
            {
                serverLog(LL_NOTICE,"%d changes in %d seconds. Saving...",
                    sp->changes, (int)sp->seconds);
                rdbSaveBackground(server.rdb_filename);
                break;
            }
         }

         /* Trigger an AOF rewrite if needed */
         if (server.rdb_child_pid == -1 &&
             server.aof_child_pid == -1 &&
             server.aof_rewrite_perc &&
             server.aof_current_size > server.aof_rewrite_min_size)
         {
            long long base = server.aof_rewrite_base_size ?
                            server.aof_rewrite_base_size : 1;
            long long growth = (server.aof_current_size*100/base) - 100;
            if (growth >= server.aof_rewrite_perc) {
                serverLog(LL_NOTICE,"Starting automatic rewriting of AOF on %lld%% growth",growth);
                rewriteAppendOnlyFileBackground();
            }
         }
    }


    /* AOF postponed flush: Try at every cron cycle if the slow fsync
     * completed. */
    if (server.aof_flush_postponed_start) flushAppendOnlyFile(0);

    /* AOF write errors: in this case we have a buffer to flush as well and
     * clear the AOF error in case of success to make the DB writable again,
     * however to try every second is enough in case of 'hz' is set to
     * an higher frequency. */
    run_with_period(1000) {
        if (server.aof_last_write_status == C_ERR)
            flushAppendOnlyFile(0);
    }

    /* Close clients that need to be closed asynchronous */
    freeClientsInAsyncFreeQueue();

    /* Clear the paused clients flag if needed. */
    clientsArePaused(); /* Don't check return value, just use the side effect. */

    /* Replication cron function -- used to reconnect to master,
     * detect transfer failures, start background RDB transfers and so forth. */
    run_with_period(1000) replicationCron();

    /* Run the Redis Cluster cron. */
    run_with_period(100) {
        if (server.cluster_enabled) clusterCron();
    }

    /* Run the Sentinel timer if we are in sentinel mode. */
    run_with_period(100) {
        if (server.sentinel_mode) sentinelTimer();
    }

    /* Cleanup expired MIGRATE cached sockets. */
    run_with_period(1000) {
        migrateCloseTimedoutSockets();
    }

    /* Start a scheduled BGSAVE if the corresponding flag is set. This is
     * useful when we are forced to postpone a BGSAVE because an AOF
     * rewrite is in progress.
     *
     * Note: this code must be after the replicationCron() call above so
     * make sure when refactoring this file to keep this order. This is useful
     * because we want to give priority to RDB savings for replication. */
    if (server.rdb_child_pid == -1 && server.aof_child_pid == -1 &&
        server.rdb_bgsave_scheduled &&
        (server.unixtime-server.lastbgsave_try > CONFIG_BGSAVE_RETRY_DELAY ||
         server.lastbgsave_status == C_OK))
    {
        if (rdbSaveBackground(server.rdb_filename) == C_OK)
            server.rdb_bgsave_scheduled = 0;
    }

#ifdef AOF_NO_COW
    if(server.aof_child_pid != -1 && server.aof_no_cow.enable)
    {
        long long start_time = ustime();
        do
        {
            aofNoCowStep();
        }
        while(ustime() - start_time < AOF_CRON_TIME);
    }
#endif

    server.cronloops++;
    return 1000/server.hz;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movl 0xd34d1(%rip), %edi     # 0x107288
testl %edi, %edi
je 0x33dc0
callq 0x672e9
callq 0x33d54
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xd2aa6(%rip)           # 0x106878
cmpl $0x63, %eax
jg 0x33df3
movl %eax, %ecx
movl 0xd2ae5(%rip), %esi     # 0x1068c4
movl $0x64, %eax
xorl %edx, %edx
idivl %ecx
movl %eax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x33e23
movq 0xd2dde(%rip), %rsi     # 0x106bd8
xorl %edi, %edi
callq 0x33956
movq 0xd2e60(%rip), %rsi     # 0x106c68
movl $0x1, %edi
callq 0x33956
movq 0xd2e57(%rip), %rsi     # 0x106c70
movl $0x2, %edi
callq 0x33956
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x26310
imulq $0xf4240, (%rbx), %rax  # imm = 0xF4240
addq 0x8(%rbx), %rax
movabsq $0x431bde82d7b634db, %rcx # imm = 0x431BDE82D7B634DB
imulq %rcx
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x12, %rdx
addl %eax, %edx
andl $0xffffff, %edx         # imm = 0xFFFFFF
movzbl 0xd2a3f(%rip), %eax     # 0x1068a3
shll $0x18, %eax
orl %edx, %eax
movl %eax, 0xd2a31(%rip)     # 0x1068a0
callq 0x3b446
cmpq 0xd2d8d(%rip), %rax     # 0x106c08
jbe 0x33e89
callq 0x3b446
movq %rax, 0xd2d7f(%rip)     # 0x106c08
callq 0x3b46a
movq %rax, 0xd2dcb(%rip)     # 0x106c60
cmpl $0x0, 0xd2a08(%rip)     # 0x1068a4
je 0x33eca
xorl %edi, %edi
callq 0x36d47
testl %eax, %eax
je 0x343ad
leaq 0x8bb2e(%rip), %rsi     # 0xbf9e2
movl $0x3, %edi
xorl %eax, %eax
callq 0x32ea6
movl $0x0, 0xd29da(%rip)     # 0x1068a4
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xd29a1(%rip)           # 0x106878
movl %eax, %ecx
movl 0xd29e5(%rip), %esi     # 0x1068c4
movl $0x1388, %eax           # imm = 0x1388
xorl %edx, %edx
idivl %ecx
movl %eax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x33f61
cmpl $0x0, 0xd2f5e(%rip)     # 0x106e58
jle 0x33f61
movl $0x8, %r15d
leaq 0x8bb39(%rip), %rbx     # 0xbfa42
xorl %r14d, %r14d
movq 0xd296d(%rip), %rcx     # 0x106880
movq -0x8(%rcx,%r15), %rax
movq (%rcx,%r15), %rdx
movq 0x48(%rax), %rcx
addq 0x28(%rax), %rcx
movq 0x48(%rdx), %r8
addq 0x28(%rdx), %r8
movq %rcx, %rdx
orq %r8, %rdx
je 0x33f4e
movq 0x38(%rax), %r9
addq 0x18(%rax), %r9
movl $0x1, %edi
movq %rbx, %rsi
movl %r14d, %edx
xorl %eax, %eax
callq 0x32ea6
incq %r14
movslq 0xd2f00(%rip), %rax     # 0x106e58
addq $0x40, %r15
cmpq %rax, %r14
jl 0x33f0c
cmpl $0x0, 0xd298c(%rip)     # 0x1068f4
jne 0x33fcd
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xd2901(%rip)           # 0x106878
movl %eax, %ecx
movl 0xd2945(%rip), %esi     # 0x1068c4
movl $0x1388, %eax           # imm = 0x1388
xorl %edx, %edx
idivl %ecx
movl %eax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x33fcd
movq 0xd2a86(%rip), %rax     # 0x106a20
movq 0x28(%rax), %rbx
movq 0xd2a93(%rip), %rax     # 0x106a38
movq 0x28(%rax), %r14
subq %r14, %rbx
callq 0x3b446
leaq 0x8babd(%rip), %rsi     # 0xbfa75
movl $0x1, %edi
movq %rbx, %rdx
movq %r14, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x32ea6
callq 0x33bec
callq 0x33ca9
cmpl $-0x1, 0xd2f9a(%rip)    # 0x106f78
jne 0x33ff7
cmpl $-0x1, 0xd2efd(%rip)    # 0x106ee4
jne 0x33ff7
cmpl $0x0, 0xd2ef0(%rip)     # 0x106ee0
je 0x33ff7
callq 0x614c5
cmpl $-0x1, 0xd2f7a(%rip)    # 0x106f78
jne 0x34016
cmpl $-0x1, 0xd2edd(%rip)    # 0x106ee4
jne 0x34016
callq 0x74300
testl %eax, %eax
je 0x340a4
xorl %ebx, %ebx
leaq 0x8(%rsp), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x26880
testl %eax, %eax
je 0x3415d
movl %eax, %ebp
movl 0x8(%rsp), %eax
movl %eax, %ecx
andl $0x7f, %ecx
movl %ecx, %edx
shll $0x18, %edx
addl $0x1000000, %edx        # imm = 0x1000000
cmpl $0x2000000, %edx        # imm = 0x2000000
cmovgel %ecx, %ebx
cmpl $-0x1, %ebp
je 0x34070
movzbl %ah, %edi
cmpl 0xd2f1a(%rip), %ebp     # 0x106f78
jne 0x34126
movl %ebx, %esi
callq 0x4e338
jmp 0x34158
callq 0x26890
movl (%rax), %edi
callq 0x26690
movl 0xd2ef6(%rip), %ecx     # 0x106f78
movl 0xd2e5b(%rip), %r8d     # 0x106ee4
leaq 0x8ba1a(%rip), %rsi     # 0xbfaaa
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x32ea6
jmp 0x34158
movslq 0xd2edd(%rip), %rax     # 0x106f88
testq %rax, %rax
jle 0x34329
movq 0xd2ec5(%rip), %rsi     # 0x106f80
movq 0xd2ea6(%rip), %rdi     # 0x106f68
movq 0xd30f7(%rip), %rcx     # 0x1071c0
movq %rcx, %r8
subq 0xd2ecd(%rip), %r8      # 0x106fa0
subq 0xd2ece(%rip), %rcx     # 0x106fa8
cmpq $0x6, %rcx
setl %cl
cmpl $0x0, 0xd2ee0(%rip)     # 0x106fc8
setne %r9b
andb %cl, %r9b
shlq $0x4, %rax
xorl %r10d, %r10d
movslq 0x8(%rsi,%r10), %rdx
cmpq %rdx, %rdi
jl 0x34118
movq (%rsi,%r10), %rcx
cmpq %rcx, %r8
setle %r11b
orb %r9b, %r11b
testb $0x1, %r11b
je 0x3430a
addq $0x10, %r10
cmpq %r10, %rax
jne 0x340f6
jmp 0x34329
cmpl 0xd2db8(%rip), %ebp     # 0x106ee4
jne 0x34137
movl %ebx, %esi
callq 0x635ae
jmp 0x34158
movl %ebp, %edi
callq 0x742ce
testl %eax, %eax
jne 0x34158
movslq %ebp, %rdx
leaq 0x8b9a4(%rip), %rsi     # 0xbfaf0
movl $0x3, %edi
xorl %eax, %eax
callq 0x32ea6
callq 0x3351d
cmpq $0x0, 0xd2d9b(%rip)     # 0x106f00
je 0x3416e
xorl %edi, %edi
callq 0x60d6c
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xd26fd(%rip)           # 0x106878
cmpl $0x3e7, %eax            # imm = 0x3E7
jg 0x3419e
movl %eax, %ecx
movl 0xd273a(%rip), %esi     # 0x1068c4
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl %ecx
movl %eax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x341ae
cmpl $-0x1, 0xd2d8f(%rip)    # 0x106f34
jne 0x341ae
xorl %edi, %edi
callq 0x60d6c
callq 0x40eee
callq 0x41c40
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xd26b3(%rip)           # 0x106878
cmpl $0x3e7, %eax            # imm = 0x3E7
jg 0x341e8
movl %eax, %ecx
movl 0xd26f0(%rip), %esi     # 0x1068c4
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl %ecx
movl %eax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x341ed
callq 0x4a80f
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xd267e(%rip)           # 0x106878
cmpl $0x63, %eax
jg 0x3421b
movl %eax, %ecx
movl 0xd26bd(%rip), %esi     # 0x1068c4
movl $0x64, %eax
xorl %edx, %edx
idivl %ecx
movl %eax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x34229
cmpl $0x0, 0xd2fc2(%rip)     # 0x1071e4
je 0x34229
callq 0x6d653
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xd2642(%rip)           # 0x106878
cmpl $0x63, %eax
jg 0x34257
movl %eax, %ecx
movl 0xd2681(%rip), %esi     # 0x1068c4
movl $0x64, %eax
xorl %edx, %edx
idivl %ecx
movl %eax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x34265
cmpl $0x0, 0xd2696(%rip)     # 0x1068f4
je 0x34265
callq 0x7fdb0
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xd2606(%rip)           # 0x106878
cmpl $0x3e7, %eax            # imm = 0x3E7
jg 0x34295
movl %eax, %ecx
movl 0xd2643(%rip), %esi     # 0x1068c4
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl %ecx
movl %eax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x3429a
callq 0x6fa1a
cmpl $-0x1, 0xd2cd7(%rip)    # 0x106f78
jne 0x342ec
cmpl $-0x1, 0xd2c3a(%rip)    # 0x106ee4
jne 0x342ec
cmpl $0x0, 0xd2d0d(%rip)     # 0x106fc0
je 0x342ec
movq 0xd2f04(%rip), %rax     # 0x1071c0
subq 0xd2ce5(%rip), %rax     # 0x106fa8
cmpq $0x5, %rax
jg 0x342d2
cmpl $0x0, 0xd2cf8(%rip)     # 0x106fc8
jne 0x342ec
movq 0xd2cb7(%rip), %rdi     # 0x106f90
callq 0x4cd9b
testl %eax, %eax
jne 0x342ec
movl $0x0, 0xd2cd4(%rip)     # 0x106fc0
incl 0xd25d2(%rip)           # 0x1068c4
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xd2579(%rip)           # 0x106878
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8b80f(%rip), %rsi     # 0xbfb20
movl $0x2, %edi
xorl %eax, %eax
callq 0x32ea6
movq 0xd2c6c(%rip), %rdi     # 0x106f90
callq 0x4cd9b
movl 0xd2bb5(%rip), %eax     # 0x106ee4
andl 0xd2c43(%rip), %eax     # 0x106f78
cmpl $-0x1, %eax
sete %cl
movl 0xd2b83(%rip), %eax     # 0x106ec4
testl %eax, %eax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x3415d
movq 0xd2b80(%rip), %rcx     # 0x106ed8
cmpq 0xd2b69(%rip), %rcx     # 0x106ec8
jle 0x3415d
movq 0xd2b64(%rip), %rsi     # 0x106ed0
cmpq $0x1, %rsi
adcq $0x0, %rsi
movslq %eax, %rdi
imulq $0x64, %rcx, %rax
cqto
idivq %rsi
addq $-0x64, %rax
cmpq %rdi, %rax
jl 0x3415d
leaq 0x8b7b0(%rip), %rsi     # 0xbfb44
movl $0x2, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x32ea6
callq 0x614c5
jmp 0x3415d
xorl %edi, %edi
callq 0x262d0