// File: /workspace/github_c_makefile_star2_O3/erikdubbelboer[P]discnt/src/server.c
// Function: serverCron
int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
    UNUSED(eventLoop);
    UNUSED(id);
    UNUSED(clientData);
    int j;

    /* 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(STAT_METRIC_COMMAND,server.stat_numcommands);
        trackInstantaneousMetric(STAT_METRIC_NET_INPUT,
                server.stat_net_input_bytes);
        trackInstantaneousMetric(STAT_METRIC_NET_OUTPUT,
                server.stat_net_output_bytes);
    }

    /* 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 information, */
    run_with_period(5000) {
        serverLog(LL_VERBOSE,
            "%lu clients connected, %zu bytes in use",
            listLength(server.clients),
            zmalloc_used_memory());

        serverLog(LL_VERBOSE,"DB: %lu keys in %lu slots HT.",dictSize(server.counters),dictSlots(server.counters));
    }

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

    /* Handle background operations on Discnt. */
    databasesCron();

    run_with_period(1000) {
        countersCron();
    }

    run_with_period(1000) {
        countersCleanupCron();
    }

    /* Check if a background saving in progress terminated. */
    if (server.ddb_child_pid != -1) {
        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. "
                    "ddb_child_pid = %d",
                    strerror(errno),
                    (int) server.ddb_child_pid);
            } else if (pid == server.ddb_child_pid) {
                backgroundSaveDoneHandler(exitcode,bysignal);
            } else {
                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,"%lld changes in %d seconds. Saving...",
                    server.dirty, (int)sp->seconds);
                ddbSaveBackground(server.ddb_filename);
                break;
            }
        }
    }

    /* 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.*/

    /* Run the Discnt Cluster cron. */
    run_with_period(100) {
        clusterCron();
    }

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

// Assembly:
pushq %rbx
subq $0x10, %rsp
movl 0x550bf(%rip), %edi     # 0x6f720
testl %edi, %edi
je 0x1a66a
callq 0x2b1c4
callq 0x1a603
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0x54a2c(%rip)           # 0x6f0a8
cmpl $0x63, %eax
jg 0x1a69e
movl %eax, %ecx
movl 0x54a5b(%rip), %esi     # 0x6f0e4
movw $0x64, %ax
xorl %edx, %edx
idivw %cx
movswl %ax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x1a6ce
movq 0x54d5b(%rip), %rsi     # 0x6f400
xorl %edi, %edi
callq 0x1a2a8
movq 0x54d85(%rip), %rsi     # 0x6f438
movl $0x1, %edi
callq 0x1a2a8
movq 0x54d7c(%rip), %rsi     # 0x6f440
movl $0x2, %edi
callq 0x1a2a8
callq 0x1fd86
cmpq 0x54d36(%rip), %rax     # 0x6f410
jbe 0x1a6e8
callq 0x1fd86
movq %rax, 0x54d28(%rip)     # 0x6f410
callq 0x1fda5
movq %rax, 0x54d3c(%rip)     # 0x6f430
cmpl $0x0, 0x549cd(%rip)     # 0x6f0c8
je 0x1a729
xorl %edi, %edi
callq 0x1c232
testl %eax, %eax
je 0x1a9d5
leaq 0x37eae(%rip), %rsi     # 0x525c1
movl $0x3, %edi
xorl %eax, %eax
callq 0x19c06
movl $0x0, 0x5499f(%rip)     # 0x6f0c8
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0x54972(%rip)           # 0x6f0a8
movl %eax, %ecx
movl 0x549a6(%rip), %esi     # 0x6f0e4
movw $0x1388, %ax            # imm = 0x1388
xorl %edx, %edx
idivw %cx
movswl %ax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x1a7a6
movq 0x54b0e(%rip), %rax     # 0x6f268
movq 0x28(%rax), %rbx
callq 0x1fd86
leaq 0x37eb7(%rip), %rsi     # 0x52621
movl $0x1, %edi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x19c06
movq 0x54f1d(%rip), %rax     # 0x6f6a0
movq 0x38(%rax), %rcx
movq 0x48(%rax), %rdx
addq 0x28(%rax), %rdx
addq 0x18(%rax), %rcx
leaq 0x37eaf(%rip), %rsi     # 0x52649
movl $0x1, %edi
xorl %eax, %eax
callq 0x19c06
callq 0x1a560
callq 0x1a5d6
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0x548eb(%rip)           # 0x6f0a8
cmpl $0x3e7, %eax            # imm = 0x3E7
jg 0x1a7e1
movl %eax, %ecx
movl 0x54918(%rip), %esi     # 0x6f0e4
movw $0x3e8, %ax             # imm = 0x3E8
xorl %edx, %edx
idivw %cx
movswl %ax, %edi
movl %esi, %eax
cltd
idivl %edi
testl %edx, %edx
jne 0x1a7fc
callq 0x31c2e
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0x548b5(%rip)           # 0x6f0a8
movl %eax, %ecx
cmpl $0x3e7, %eax            # imm = 0x3E7
jg 0x1a817
movl 0x548e2(%rip), %esi     # 0x6f0e4
movw $0x3e8, %ax             # imm = 0x3E8
xorl %edx, %edx
idivw %cx
movswl %ax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x1a81c
callq 0x31e4e
cmpl $-0x1, 0x54f15(%rip)    # 0x6f738
je 0x1a881
xorl %ebx, %ebx
leaq 0xc(%rsp), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x12230
testl %eax, %eax
je 0x1a972
movl 0xc(%rsp), %ecx
movl %ecx, %edx
andl $0x7f, %edx
movl %edx, %esi
shll $0x18, %esi
addl $0x1000000, %esi        # imm = 0x1000000
cmpl $0x2000000, %esi        # imm = 0x2000000
cmovgel %edx, %ebx
cmpl $-0x1, %eax
je 0x1a8fc
cmpl 0x54ecc(%rip), %eax     # 0x6f738
jne 0x1a926
movzbl %ch, %edi
movl %ebx, %esi
callq 0x333f8
jmp 0x1a93c
movslq 0x54ec0(%rip), %rax     # 0x6f748
testq %rax, %rax
jle 0x1a972
movq 0x54ea8(%rip), %rsi     # 0x6f740
movq 0x54e89(%rip), %rdx     # 0x6f728
movq 0x54e2a(%rip), %rcx     # 0x6f6d0
movq %rcx, %rdi
subq 0x54eb0(%rip), %rdi     # 0x6f760
subq 0x54eb1(%rip), %rcx     # 0x6f768
cmpq $0x6, %rcx
setl %cl
cmpl $0x0, 0x54ebf(%rip)     # 0x6f784
setne %r8b
andb %cl, %r8b
shlq $0x4, %rax
xorl %r9d, %r9d
movslq 0x8(%rsi,%r9), %rcx
cmpq %rcx, %rdx
jl 0x1a8f1
movq (%rsi,%r9), %rcx
cmpq %rcx, %rdi
setle %r10b
orb %r8b, %r10b
testb $0x1, %r10b
je 0x1a953
addq $0x10, %r9
cmpq %r9, %rax
jne 0x1a8d3
jmp 0x1a972
callq 0x120d0
movl (%rax), %edi
callq 0x128e0
movl 0x54e2a(%rip), %ecx     # 0x6f738
leaq 0x37d52(%rip), %rsi     # 0x52667
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x19c06
jmp 0x1a93c
movslq %eax, %rdx
leaq 0x37d69(%rip), %rsi     # 0x52699
movl $0x3, %edi
xorl %eax, %eax
callq 0x19c06
cmpl $-0x1, 0x54df5(%rip)    # 0x6f738
je 0x1a94c
callq 0x1944e
jmp 0x1a972
callq 0x19446
jmp 0x1a972
leaq 0x37d6f(%rip), %rsi     # 0x526c9
movl $0x2, %edi
xorl %eax, %eax
callq 0x19c06
movq 0x54de3(%rip), %rdi     # 0x6f750
callq 0x32b42
callq 0x22db4
callq 0x23a51
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0x5471f(%rip)           # 0x6f0a8
cmpl $0x63, %eax
jg 0x1a9ab
movl %eax, %ecx
movl 0x5474e(%rip), %esi     # 0x6f0e4
movw $0x64, %ax
xorl %edx, %edx
idivw %cx
movswl %ax, %edi
movl %esi, %eax
cltd
idivl %edi
testl %edx, %edx
jne 0x1a9c5
callq 0x2da65
movl 0x5472e(%rip), %esi     # 0x6f0e4
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0x546e5(%rip)           # 0x6f0a8
movl %eax, %ecx
incl %esi
movl %esi, 0x54717(%rip)     # 0x6f0e4
movl %ecx, %eax
addq $0x10, %rsp
popq %rbx
retq
xorl %edi, %edi
callq 0x12860