// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/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;

        if ((pid = wait3(&statloc,WNOHANG,NULL)) != 0) {
            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;
    }

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movl 0xd1644(%rip), %edi     # 0x1022e8
testl %edi, %edi
je 0x30cad
callq 0x636cf
callq 0x30c41
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xd0c09(%rip)           # 0x1018c8
cmpl $0x63, %eax
jg 0x30ce1
movl %eax, %ecx
movl 0xd0c48(%rip), %esi     # 0x101914
movw $0x64, %ax
xorl %edx, %edx
idivw %cx
movswl %ax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x30d11
movq 0xd0f50(%rip), %rsi     # 0x101c38
xorl %edi, %edi
callq 0x30810
movq 0xd0fd2(%rip), %rsi     # 0x101cc8
movl $0x1, %edi
callq 0x30810
movq 0xd0fc9(%rip), %rsi     # 0x101cd0
movl $0x2, %edi
callq 0x30810
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x26300
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 0xd0ba1(%rip), %eax     # 0x1018f3
shll $0x18, %eax
orl %edx, %eax
movl %eax, 0xd0b93(%rip)     # 0x1018f0
callq 0x3847a
cmpq 0xd0eff(%rip), %rax     # 0x101c68
jbe 0x30d77
callq 0x3847a
movq %rax, 0xd0ef1(%rip)     # 0x101c68
callq 0x3849e
movq %rax, 0xd0f3d(%rip)     # 0x101cc0
cmpl $0x0, 0xd0b6a(%rip)     # 0x1018f4
je 0x30db8
xorl %edi, %edi
callq 0x33cd9
testl %eax, %eax
je 0x312d4
leaq 0x8bcb2(%rip), %rsi     # 0xbca54
movl $0x3, %edi
xorl %eax, %eax
callq 0x2fdad
movl $0x0, 0xd0b3c(%rip)     # 0x1018f4
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xd0b03(%rip)           # 0x1018c8
movl %eax, %ecx
movl 0xd0b47(%rip), %esi     # 0x101914
movw $0x1388, %ax            # imm = 0x1388
xorl %edx, %edx
idivw %cx
movswl %ax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
sete %cl
movl 0xd10cf(%rip), %eax     # 0x101eb8
testl %eax, %eax
setg %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x30e63
movl $0x8, %r15d
movq 0xd0ace(%rip), %rdx     # 0x1018d0
leaq 0x8bcab(%rip), %rbx     # 0xbcab4
xorl %r14d, %r14d
movq -0x8(%rdx,%r15), %rsi
movq (%rdx,%r15), %rdi
movq 0x48(%rsi), %rcx
addq 0x28(%rsi), %rcx
movq 0x48(%rdi), %r8
addq 0x28(%rdi), %r8
movq %rcx, %rdi
orq %r8, %rdi
je 0x30e54
movq 0x38(%rsi), %r9
addq 0x18(%rsi), %r9
movl $0x1, %edi
movq %rbx, %rsi
movl %r14d, %edx
xorl %eax, %eax
callq 0x2fdad
movq 0xd0a82(%rip), %rdx     # 0x1018d0
movl 0xd1064(%rip), %eax     # 0x101eb8
incq %r14
movslq %eax, %rcx
addq $0x40, %r15
cmpq %rcx, %r14
jl 0x30e0c
cmpl $0x0, 0xd0ada(%rip)     # 0x101944
jne 0x30ed0
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xd0a4f(%rip)           # 0x1018c8
movl %eax, %ecx
movl 0xd0a93(%rip), %esi     # 0x101914
movw $0x1388, %ax            # imm = 0x1388
xorl %edx, %edx
idivw %cx
movswl %ax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x30ed0
movq 0xd0bd3(%rip), %rax     # 0x101a70
movq 0x28(%rax), %rbx
movq 0xd0be0(%rip), %rax     # 0x101a88
movq 0x28(%rax), %r14
subq %r14, %rbx
callq 0x3847a
leaq 0x8bc2c(%rip), %rsi     # 0xbcae7
movl $0x1, %edi
movq %rbx, %rdx
movq %r14, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x2fdad
callq 0x30abf
callq 0x30b7c
movl 0xd10f8(%rip), %ecx     # 0x101fd8
movl 0xd105e(%rip), %eax     # 0x101f44
cmpl $-0x1, %ecx
jne 0x30f0a
cmpl $-0x1, %eax
jne 0x30f0a
cmpl $0x0, 0xd1049(%rip)     # 0x101f40
je 0x30f0a
callq 0x5d8b1
movl 0xd10d4(%rip), %ecx     # 0x101fd8
movl 0xd103a(%rip), %eax     # 0x101f44
cmpl $-0x1, %ecx
jne 0x30f21
cmpl $-0x1, %eax
jne 0x30f21
callq 0x70895
testl %eax, %eax
je 0x30faf
xorl %ebx, %ebx
leaq 0x8(%rsp), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x26870
testl %eax, %eax
je 0x31068
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 0x30f7b
movzbl %ah, %edi
cmpl 0xd106f(%rip), %ebp     # 0x101fd8
jne 0x31031
movl %ebx, %esi
callq 0x4ac4a
jmp 0x31063
callq 0x26880
movl (%rax), %edi
callq 0x26680
movl 0xd104b(%rip), %ecx     # 0x101fd8
movl 0xd0fb0(%rip), %r8d     # 0x101f44
leaq 0x8bb81(%rip), %rsi     # 0xbcb1c
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2fdad
jmp 0x31063
movslq 0xd1032(%rip), %rax     # 0x101fe8
testq %rax, %rax
jle 0x31250
movq 0xd101a(%rip), %rsi     # 0x101fe0
movq 0xd0ffb(%rip), %rdi     # 0x101fc8
movq 0xd124c(%rip), %rcx     # 0x102220
movq %rcx, %r8
subq 0xd1022(%rip), %r8      # 0x102000
subq 0xd1023(%rip), %rcx     # 0x102008
cmpq $0x6, %rcx
setl %cl
cmpl $0x0, 0xd1035(%rip)     # 0x102028
setne %r9b
andb %cl, %r9b
shlq $0x4, %rax
xorl %r10d, %r10d
movslq 0x8(%rsi,%r10), %rdx
cmpq %rdx, %rdi
jl 0x31023
movq (%rsi,%r10), %rcx
cmpq %rcx, %r8
setle %r11b
orb %r9b, %r11b
testb $0x1, %r11b
je 0x31231
addq $0x10, %r10
cmpq %r10, %rax
jne 0x31001
jmp 0x31250
cmpl 0xd0f0d(%rip), %ebp     # 0x101f44
jne 0x31042
movl %ebx, %esi
callq 0x5f9c9
jmp 0x31063
movl %ebp, %edi
callq 0x70863
testl %eax, %eax
jne 0x31063
movslq %ebp, %rdx
leaq 0x8bb0b(%rip), %rsi     # 0xbcb62
movl $0x3, %edi
xorl %eax, %eax
callq 0x2fdad
callq 0x30423
cmpq $0x0, 0xd0ef0(%rip)     # 0x101f60
je 0x31079
xorl %edi, %edi
callq 0x5d159
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xd0842(%rip)           # 0x1018c8
cmpl $0x3e7, %eax            # imm = 0x3E7
jg 0x310aa
movl %eax, %ecx
movl 0xd087f(%rip), %esi     # 0x101914
movw $0x3e8, %ax             # imm = 0x3E8
xorl %edx, %edx
idivw %cx
movswl %ax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x310ba
cmpl $-0x1, 0xd0ee3(%rip)    # 0x101f94
jne 0x310ba
xorl %edi, %edi
callq 0x5d159
callq 0x3db32
callq 0x3e869
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xd07f7(%rip)           # 0x1018c8
cmpl $0x3e7, %eax            # imm = 0x3E7
jg 0x310f5
movl %eax, %ecx
movl 0xd0834(%rip), %esi     # 0x101914
movw $0x3e8, %ax             # imm = 0x3E8
xorl %edx, %edx
idivw %cx
movswl %ax, %edi
movl %esi, %eax
cltd
idivl %edi
testl %edx, %edx
jne 0x31109
callq 0x47529
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xd07c1(%rip)           # 0x1018c8
movl %eax, %ecx
cmpl $0x63, %ecx
jle 0x31119
cmpl $0x0, 0xd112f(%rip)     # 0x102244
jne 0x3113d
jmp 0x31156
movl 0xd07f5(%rip), %esi     # 0x101914
movw $0x64, %ax
xorl %edx, %edx
idivw %cx
movswl %ax, %edi
movl %esi, %eax
cltd
idivl %edi
testl %edx, %edx
jne 0x31161
cmpl $0x0, 0xd1109(%rip)     # 0x102244
je 0x31161
callq 0x69af4
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xd0779(%rip)           # 0x1018c8
movl %eax, %ecx
cmpl $0x63, %eax
jle 0x31161
cmpl $0x0, 0xd07e7(%rip)     # 0x101944
jne 0x31185
jmp 0x31199
movl 0xd07ad(%rip), %esi     # 0x101914
movw $0x64, %ax
xorl %edx, %edx
idivw %cx
movswl %ax, %edi
movl %esi, %eax
cltd
idivl %edi
testl %edx, %edx
jne 0x311a1
cmpl $0x0, 0xd07c1(%rip)     # 0x101944
je 0x311a1
callq 0x7c34d
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xd0731(%rip)           # 0x1018c8
movl %eax, %ecx
cmpl $0x3e7, %ecx            # imm = 0x3E7
jg 0x311bc
movl 0xd076d(%rip), %esi     # 0x101914
movw $0x3e8, %ax             # imm = 0x3E8
xorl %edx, %edx
idivw %cx
movswl %ax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x311c1
callq 0x6bec5
cmpl $-0x1, 0xd0e10(%rip)    # 0x101fd8
jne 0x31213
cmpl $-0x1, 0xd0d73(%rip)    # 0x101f44
jne 0x31213
cmpl $0x0, 0xd0e46(%rip)     # 0x102020
je 0x31213
movq 0xd103d(%rip), %rax     # 0x102220
subq 0xd0e1e(%rip), %rax     # 0x102008
cmpq $0x5, %rax
jg 0x311f9
cmpl $0x0, 0xd0e31(%rip)     # 0x102028
jne 0x31213
movq 0xd0df0(%rip), %rdi     # 0x101ff0
callq 0x49797
testl %eax, %eax
jne 0x31213
movl $0x0, 0xd0e0d(%rip)     # 0x102020
incl 0xd06fb(%rip)           # 0x101914
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xd06a2(%rip)           # 0x1018c8
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8b95a(%rip), %rsi     # 0xbcb92
movl $0x2, %edi
xorl %eax, %eax
callq 0x2fdad
movq 0xd0da5(%rip), %rdi     # 0x101ff0
callq 0x49797
movl 0xd0cee(%rip), %eax     # 0x101f44
andl 0xd0d7c(%rip), %eax     # 0x101fd8
cmpl $-0x1, %eax
sete %cl
movl 0xd0cbc(%rip), %eax     # 0x101f24
testl %eax, %eax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x31068
movq 0xd0cb9(%rip), %rcx     # 0x101f38
cmpq 0xd0ca2(%rip), %rcx     # 0x101f28
jle 0x31068
movq 0xd0c9d(%rip), %rsi     # 0x101f30
cmpq $0x1, %rsi
adcq $0x0, %rsi
movslq %eax, %rdi
imulq $0x64, %rcx, %rax
cqto
idivq %rsi
addq $-0x64, %rax
cmpq %rdi, %rax
jl 0x31068
leaq 0x8b8fb(%rip), %rsi     # 0xbcbb6
movl $0x2, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2fdad
callq 0x5d8b1
jmp 0x31068
xorl %edi, %edi
callq 0x262c0