// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %rbx
pushq %rax
movl 0x543e0(%rip), %edi     # 0x6a720
testl %edi, %edi
je 0x16349
callq 0x24be0
callq 0x1631a
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0x53d4d(%rip)           # 0x6a0a8
cmpl $0x63, %eax
jg 0x1637d
movl %eax, %ecx
movl 0x53d7c(%rip), %esi     # 0x6a0e4
movw $0x64, %ax
xorl %edx, %edx
idivw %cx
movswl %ax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x163a9
movq 0x5407c(%rip), %rsi     # 0x6a400
xorl %edi, %edi
callq 0x160aa
movq 0x540a6(%rip), %rsi     # 0x6a438
pushq $0x1
popq %rdi
callq 0x160aa
movq 0x5409f(%rip), %rsi     # 0x6a440
pushq $0x2
popq %rdi
callq 0x160aa
callq 0x1acf0
cmpq 0x5405b(%rip), %rax     # 0x6a410
jbe 0x163c3
callq 0x1acf0
movq %rax, 0x5404d(%rip)     # 0x6a410
callq 0x1ad0f
movq %rax, 0x54061(%rip)     # 0x6a430
cmpl $0x0, 0x53cf2(%rip)     # 0x6a0c8
je 0x163ff
xorl %edi, %edi
callq 0x17d73
testl %eax, %eax
je 0x16691
leaq 0x360f3(%rip), %rsi     # 0x4c4e1
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x15b9e
andl $0x0, 0x53cc9(%rip)     # 0x6a0c8
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0x53c9c(%rip)           # 0x6a0a8
movl %eax, %ecx
movl 0x53cd0(%rip), %esi     # 0x6a0e4
movw $0x1388, %ax            # imm = 0x1388
xorl %edx, %edx
idivw %cx
movswl %ax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x16479
movq 0x53e38(%rip), %rax     # 0x6a268
movq 0x28(%rax), %rbx
callq 0x1acf0
leaq 0x36101(%rip), %rsi     # 0x4c541
pushq $0x1
popq %rbp
movl %ebp, %edi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x15b9e
movq 0x54247(%rip), %rax     # 0x6a6a0
movq 0x38(%rax), %rcx
movq 0x48(%rax), %rdx
addq 0x28(%rax), %rdx
addq 0x18(%rax), %rcx
leaq 0x360f9(%rip), %rsi     # 0x4c569
movl %ebp, %edi
xorl %eax, %eax
callq 0x15b9e
callq 0x16296
callq 0x16304
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0x53c18(%rip)           # 0x6a0a8
cmpl $0x3e7, %eax            # imm = 0x3E7
jg 0x164b4
movl %eax, %ecx
movl 0x53c45(%rip), %esi     # 0x6a0e4
movw $0x3e8, %ax             # imm = 0x3E8
xorl %edx, %edx
idivw %cx
movswl %ax, %edi
movl %esi, %eax
cltd
idivl %edi
testl %edx, %edx
jne 0x164cf
callq 0x2aaa9
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0x53be2(%rip)           # 0x6a0a8
movl %eax, %ecx
cmpl $0x3e7, %eax            # imm = 0x3E7
jg 0x164ea
movl 0x53c0f(%rip), %esi     # 0x6a0e4
movw $0x3e8, %ax             # imm = 0x3E8
xorl %edx, %edx
idivw %cx
movswl %ax, %ecx
movl %esi, %eax
cltd
idivl %ecx
testl %edx, %edx
jne 0x164ef
callq 0x2acbc
cmpl $-0x1, 0x54242(%rip)    # 0x6a738
je 0x16552
xorl %ebx, %ebx
leaq 0x4(%rsp), %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x12230
testl %eax, %eax
je 0x1662d
movl 0x4(%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 0x165cd
cmpl 0x541fb(%rip), %eax     # 0x6a738
jne 0x16614
movzbl %ch, %edi
movl %ebx, %esi
callq 0x2bed2
jmp 0x16628
movl 0x541f0(%rip), %eax     # 0x6a748
movq 0x541e1(%rip), %rsi     # 0x6a740
movq 0x5416a(%rip), %rcx     # 0x6a6d0
movq %rcx, %rdi
subq 0x541f0(%rip), %rdi     # 0x6a760
subq 0x541f1(%rip), %rcx     # 0x6a768
cmpq $0x6, %rcx
setl %cl
cmpl $0x0, 0x541ff(%rip)     # 0x6a784
movq 0x5419c(%rip), %rdx     # 0x6a728
setne %r8b
andb %cl, %r8b
xorl %r9d, %r9d
testl %eax, %eax
cmovlel %r9d, %eax
shlq $0x4, %rax
cmpq %r9, %rax
je 0x1662d
movslq 0x8(%rsi,%r9), %rcx
cmpq %rcx, %rdx
jl 0x165c7
movq (%rsi,%r9), %rcx
cmpq %rcx, %rdi
setle %r10b
orb %r8b, %r10b
testb $0x1, %r10b
je 0x165f5
addq $0x10, %r9
jmp 0x165a0
callq 0x120d0
movl (%rax), %edi
callq 0x128e0
movl 0x54159(%rip), %ecx     # 0x6a738
leaq 0x35fa1(%rip), %rsi     # 0x4c587
pushq $0x3
popq %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x15b9e
jmp 0x16628
leaq 0x35fed(%rip), %rsi     # 0x4c5e9
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x15b9e
movq 0x54143(%rip), %rdi     # 0x6a750
callq 0x2b751
jmp 0x1662d
movslq %eax, %rdx
leaq 0x35f9b(%rip), %rsi     # 0x4c5b9
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x15b9e
callq 0x1608a
callq 0x1d6e4
callq 0x1e085
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0x53a64(%rip)           # 0x6a0a8
cmpl $0x63, %eax
jg 0x16666
movl %eax, %ecx
movl 0x53a93(%rip), %esi     # 0x6a0e4
movw $0x64, %ax
xorl %edx, %edx
idivw %cx
movswl %ax, %edi
movl %esi, %eax
cltd
idivl %edi
testl %edx, %edx
jne 0x16680
callq 0x27048
movl 0x53a73(%rip), %esi     # 0x6a0e4
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0x53a2a(%rip)           # 0x6a0a8
movl %eax, %ecx
incl %esi
movl %esi, 0x53a5c(%rip)     # 0x6a0e4
movl %ecx, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
xorl %edi, %edi
callq 0x12860