// File: /workspace/github_c_makefile_star2_O2/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
pushq %rax
movl 0xce113(%rip), %edi     # 0xfa2e8
testl %edi, %edi
je 0x2c1de
callq 0x595b6
callq 0x2c1ab
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xcd6d8(%rip)           # 0xf98c8
cmpl $0x63, %eax
jg 0x2c212
movl %eax, %ecx
movl 0xcd717(%rip), %esi     # 0xf9914
movw $0x64, %ax
xorl %edx, %edx
idivw %cx
movswl %ax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x2c23e
movq 0xcda1f(%rip), %rsi     # 0xf9c38
xorl %edi, %edi
callq 0x2be84
movq 0xcdaa1(%rip), %rsi     # 0xf9cc8
pushq $0x1
popq %rdi
callq 0x2be84
movq 0xcda9a(%rip), %rsi     # 0xf9cd0
pushq $0x2
popq %rdi
callq 0x2be84
callq 0x2be6d
movzbl 0xcd6a9(%rip), %ecx     # 0xf98f3
shll $0x18, %ecx
orl %eax, %ecx
movl %ecx, 0xcd69b(%rip)     # 0xf98f0
callq 0x32960
cmpq 0xcda07(%rip), %rax     # 0xf9c68
jbe 0x2c26f
callq 0x32960
movq %rax, 0xcd9f9(%rip)     # 0xf9c68
callq 0x32984
movq %rax, 0xcda45(%rip)     # 0xf9cc0
cmpl $0x0, 0xcd672(%rip)     # 0xf98f4
je 0x2c2ab
xorl %edi, %edi
callq 0x2ee95
testl %eax, %eax
je 0x2c7ad
leaq 0x826aa(%rip), %rsi     # 0xae944
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
andl $0x0, 0xcd649(%rip)     # 0xf98f4
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xcd610(%rip)           # 0xf98c8
movl %eax, %ecx
movl 0xcd654(%rip), %esi     # 0xf9914
movw $0x1388, %ax            # imm = 0x1388
xorl %edx, %edx
idivw %cx
movswl %ax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
je 0x2c3f1
cmpl $0x0, 0xcd664(%rip)     # 0xf9944
jne 0x2c344
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xcd5d9(%rip)           # 0xf98c8
movl %eax, %ecx
movl 0xcd61d(%rip), %esi     # 0xf9914
movw $0x1388, %ax            # imm = 0x1388
xorl %edx, %edx
idivw %cx
movswl %ax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x2c344
movq 0xcd75d(%rip), %rax     # 0xf9a70
movq 0x28(%rax), %rbx
movq 0xcd76a(%rip), %rax     # 0xf9a88
movq 0x28(%rax), %r14
subq %r14, %rbx
callq 0x32960
leaq 0x826a6(%rip), %rsi     # 0xae9d7
pushq $0x1
popq %rdi
movq %rbx, %rdx
movq %r14, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x2b699
callq 0x2c08c
callq 0x2c10d
movl 0xcdc84(%rip), %ecx     # 0xf9fd8
movl 0xcdbea(%rip), %eax     # 0xf9f44
cmpl $-0x1, %ecx
jne 0x2c37e
cmpl $-0x1, %eax
jne 0x2c37e
cmpl $0x0, 0xcdbd5(%rip)     # 0xf9f40
je 0x2c37e
callq 0x541f2
movl 0xcdc60(%rip), %ecx     # 0xf9fd8
movl 0xcdbc6(%rip), %eax     # 0xf9f44
cmpl $-0x1, %ecx
jne 0x2c395
cmpl $-0x1, %eax
jne 0x2c395
callq 0x65128
testl %eax, %eax
je 0x2c494
xorl %ebx, %ebx
leaq 0x4(%rsp), %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x26870
testl %eax, %eax
je 0x2c548
movl %eax, %ebp
movl 0x4(%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 0x2c462
movzbl %ah, %edi
cmpl 0xcdbf9(%rip), %ebp     # 0xf9fd8
jne 0x2c513
movl %ebx, %esi
callq 0x42d1f
jmp 0x2c543
pushq $0x8
popq %r15
movl 0xcdabd(%rip), %eax     # 0xf9eb8
leaq 0x825a2(%rip), %rbx     # 0xae9a4
pushq $0x1
popq %rbp
xorl %r14d, %r14d
movslq %eax, %rcx
cmpq %rcx, %r14
jge 0x2c2d9
movq 0xcd4b5(%rip), %rcx     # 0xf98d0
movq -0x8(%rcx,%r15), %rdx
movq (%rcx,%r15), %rsi
movq 0x48(%rdx), %rcx
addq 0x28(%rdx), %rcx
movq 0x48(%rsi), %r8
addq 0x28(%rsi), %r8
movq %rcx, %rsi
orq %r8, %rsi
je 0x2c459
movq 0x38(%rdx), %r9
addq 0x18(%rdx), %r9
movl %ebp, %edi
movq %rbx, %rsi
movl %r14d, %edx
xorl %eax, %eax
callq 0x2b699
movl 0xcda5f(%rip), %eax     # 0xf9eb8
incq %r14
addq $0x40, %r15
jmp 0x2c408
callq 0x26880
movl (%rax), %edi
callq 0x26680
movl 0xcdb64(%rip), %ecx     # 0xf9fd8
movl 0xcdac9(%rip), %r8d     # 0xf9f44
leaq 0x8258a(%rip), %rsi     # 0xaea0c
pushq $0x3
popq %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2b699
jmp 0x2c543
movl 0xcdb4e(%rip), %eax     # 0xf9fe8
movq 0xcdb3f(%rip), %rsi     # 0xf9fe0
movq 0xcdd78(%rip), %rcx     # 0xfa220
movq %rcx, %rdi
subq 0xcdb4e(%rip), %rdi     # 0xfa000
subq 0xcdb4f(%rip), %rcx     # 0xfa008
cmpq $0x6, %rcx
setl %cl
cmpl $0x0, 0xcdb61(%rip)     # 0xfa028
movq 0xcdafa(%rip), %r8      # 0xf9fc8
setne %r9b
andb %cl, %r9b
xorl %r10d, %r10d
testl %eax, %eax
cmovlel %r10d, %eax
shlq $0x4, %rax
cmpq %r10, %rax
je 0x2c72b
movslq 0x8(%rsi,%r10), %rdx
cmpq %rdx, %r8
jl 0x2c50d
movq (%rsi,%r10), %rcx
cmpq %rcx, %rdi
setle %r11b
orb %r9b, %r11b
testb $0x1, %r11b
je 0x2c70e
addq $0x10, %r10
jmp 0x2c4e2
cmpl 0xcda2b(%rip), %ebp     # 0xf9f44
jne 0x2c524
movl %ebx, %esi
callq 0x55f29
jmp 0x2c543
movl %ebp, %edi
callq 0x650f8
testl %eax, %eax
jne 0x2c543
movslq %ebp, %rdx
leaq 0x82519(%rip), %rsi     # 0xaea52
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
callq 0x2bb7f
cmpq $0x0, 0xcda10(%rip)     # 0xf9f60
je 0x2c559
xorl %edi, %edi
callq 0x53b99
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xcd362(%rip)           # 0xf98c8
cmpl $0x3e7, %eax            # imm = 0x3E7
jg 0x2c58a
movl %eax, %ecx
movl 0xcd39f(%rip), %esi     # 0xf9914
movw $0x3e8, %ax             # imm = 0x3E8
xorl %edx, %edx
idivw %cx
movswl %ax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x2c59a
cmpl $-0x1, 0xcda03(%rip)    # 0xf9f94
jne 0x2c59a
xorl %edi, %edi
callq 0x53b99
callq 0x378fd
callq 0x38320
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xcd317(%rip)           # 0xf98c8
cmpl $0x3e7, %eax            # imm = 0x3E7
jg 0x2c5d5
movl %eax, %ecx
movl 0xcd354(%rip), %esi     # 0xf9914
movw $0x3e8, %ax             # imm = 0x3E8
xorl %edx, %edx
idivw %cx
movswl %ax, %edi
movl %esi, %eax
cltd
idivl %edi
testl %edx, %edx
jne 0x2c5e9
callq 0x3ff24
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xcd2e1(%rip)           # 0xf98c8
movl %eax, %ecx
cmpl $0x63, %ecx
jle 0x2c5f9
cmpl $0x0, 0xcdc4f(%rip)     # 0xfa244
jne 0x2c61d
jmp 0x2c636
movl 0xcd315(%rip), %esi     # 0xf9914
movw $0x64, %ax
xorl %edx, %edx
idivw %cx
movswl %ax, %edi
movl %esi, %eax
cltd
idivl %edi
testl %edx, %edx
jne 0x2c641
cmpl $0x0, 0xcdc29(%rip)     # 0xfa244
je 0x2c641
callq 0x5ee28
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xcd299(%rip)           # 0xf98c8
movl %eax, %ecx
cmpl $0x63, %eax
jle 0x2c641
cmpl $0x0, 0xcd307(%rip)     # 0xf9944
jne 0x2c665
jmp 0x2c679
movl 0xcd2cd(%rip), %esi     # 0xf9914
movw $0x64, %ax
xorl %edx, %edx
idivw %cx
movswl %ax, %edi
movl %esi, %eax
cltd
idivl %edi
testl %edx, %edx
jne 0x2c681
cmpl $0x0, 0xcd2e1(%rip)     # 0xf9944
je 0x2c681
callq 0x6f893
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xcd251(%rip)           # 0xf98c8
movl %eax, %ecx
cmpl $0x3e7, %ecx            # imm = 0x3E7
jg 0x2c69c
movl 0xcd28d(%rip), %esi     # 0xf9914
movw $0x3e8, %ax             # imm = 0x3E8
xorl %edx, %edx
idivw %cx
movswl %ax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x2c6a1
callq 0x60f80
cmpl $-0x1, 0xcd930(%rip)    # 0xf9fd8
jne 0x2c6f0
cmpl $-0x1, 0xcd893(%rip)    # 0xf9f44
jne 0x2c6f0
cmpl $0x0, 0xcd966(%rip)     # 0xfa020
je 0x2c6f0
movq 0xcdb5d(%rip), %rax     # 0xfa220
subq 0xcd93e(%rip), %rax     # 0xfa008
cmpq $0x5, %rax
jg 0x2c6d9
cmpl $0x0, 0xcd951(%rip)     # 0xfa028
jne 0x2c6f0
movq 0xcd910(%rip), %rdi     # 0xf9ff0
callq 0x41b62
testl %eax, %eax
jne 0x2c6f0
andl $0x0, 0xcd930(%rip)     # 0xfa020
incl 0xcd21e(%rip)           # 0xf9914
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0xcd1c5(%rip)           # 0xf98c8
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8236d(%rip), %rsi     # 0xaea82
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x2b699
movq 0xcd8ca(%rip), %rdi     # 0xf9ff0
callq 0x41b62
movl 0xcd813(%rip), %eax     # 0xf9f44
andl 0xcd8a1(%rip), %eax     # 0xf9fd8
cmpl $-0x1, %eax
sete %cl
movl 0xcd7e1(%rip), %eax     # 0xf9f24
testl %eax, %eax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x2c548
movq 0xcd7de(%rip), %rcx     # 0xf9f38
cmpq 0xcd7c7(%rip), %rcx     # 0xf9f28
jle 0x2c548
movq 0xcd7c2(%rip), %rsi     # 0xf9f30
cmpq $0x1, %rsi
adcq $0x0, %rsi
movslq %eax, %rdi
imulq $0x64, %rcx, %rax
cqto
idivq %rsi
addq $-0x64, %rax
cmpq %rdi, %rax
jl 0x2c548
leaq 0x82310(%rip), %rsi     # 0xaeaa6
pushq $0x2
popq %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2b699
callq 0x541f2
jmp 0x2c548
xorl %edi, %edi
callq 0x262c0