// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
cmpl $0x0, 0xa5d05(%rip)     # 0xbf780
je 0x19a88
movl 0xa5cfd(%rip), %edi     # 0xbf780
callq 0x31290
callq 0x19a30
movl $0x3e8, %eax            # imm = 0x3E8
cltd
idivl 0xa566f(%rip)           # 0xbf108
movl %eax, %ecx
movl $0x64, %eax
cmpl %ecx, %eax
jle 0x19ad0
movl 0xa569a(%rip), %eax     # 0xbf144
movl %eax, -0x3c(%rbp)
movl $0x3e8, %eax            # imm = 0x3E8
cltd
idivl 0xa564f(%rip)           # 0xbf108
movl %eax, %ecx
movl $0x64, %eax
cltd
idivl %ecx
movl %eax, %ecx
movl -0x3c(%rbp), %eax
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x19b00
movq 0xa5989(%rip), %rsi     # 0xbf460
xorl %edi, %edi
callq 0x194a0
movq 0xa59b3(%rip), %rsi     # 0xbf498
movl $0x1, %edi
callq 0x194a0
movq 0xa59aa(%rip), %rsi     # 0xbf4a0
movl $0x2, %edi
callq 0x194a0
callq 0x20de0
cmpq 0xa5964(%rip), %rax     # 0xbf470
jbe 0x19b1a
callq 0x20de0
movq %rax, 0xa5956(%rip)     # 0xbf470
callq 0x20e50
movq %rax, 0xa596a(%rip)     # 0xbf490
cmpl $0x0, 0xa55fb(%rip)     # 0xbf128
je 0x19b5f
xorl %edi, %edi
callq 0x1beb0
cmpl $0x0, %eax
jne 0x19b42
xorl %edi, %edi
callq 0x12870
movl $0x3, %edi
leaq 0x89a43(%rip), %rsi     # 0xa3591
movb $0x0, %al
callq 0x18b10
movl $0x0, 0xa55c9(%rip)     # 0xbf128
movl $0x3e8, %eax            # imm = 0x3E8
cltd
idivl 0xa559d(%rip)           # 0xbf108
movl %eax, %ecx
movl $0x1388, %eax           # imm = 0x1388
cmpl %ecx, %eax
jle 0x19ba2
movl 0xa55c8(%rip), %eax     # 0xbf144
movl %eax, -0x40(%rbp)
movl $0x3e8, %eax            # imm = 0x3E8
cltd
idivl 0xa557d(%rip)           # 0xbf108
movl %eax, %ecx
movl $0x1388, %eax           # imm = 0x1388
cltd
idivl %ecx
movl %eax, %ecx
movl -0x40(%rbp), %eax
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x19c0f
movq 0xa571f(%rip), %rax     # 0xbf2c8
movq 0x28(%rax), %rax
movq %rax, -0x48(%rbp)
callq 0x20de0
movq -0x48(%rbp), %rdx
movq %rax, %rcx
movl $0x1, %edi
leaq 0x89a28(%rip), %rsi     # 0xa35f1
movb $0x0, %al
callq 0x18b10
movq 0xa5b29(%rip), %rax     # 0xbf700
movq 0x28(%rax), %rdx
movq 0xa5b1e(%rip), %rax     # 0xbf700
addq 0x48(%rax), %rdx
movq 0xa5b13(%rip), %rax     # 0xbf700
movq 0x18(%rax), %rcx
movq 0xa5b08(%rip), %rax     # 0xbf700
addq 0x38(%rax), %rcx
movl $0x1, %edi
leaq 0x89a11(%rip), %rsi     # 0xa3619
movb $0x0, %al
callq 0x18b10
callq 0x19940
callq 0x19a10
movl $0x3e8, %eax            # imm = 0x3E8
cltd
idivl 0xa54e3(%rip)           # 0xbf108
movl %eax, %ecx
movl $0x3e8, %eax            # imm = 0x3E8
cmpl %ecx, %eax
jle 0x19c5c
movl 0xa550e(%rip), %eax     # 0xbf144
movl %eax, -0x4c(%rbp)
movl $0x3e8, %eax            # imm = 0x3E8
cltd
idivl 0xa54c3(%rip)           # 0xbf108
movl %eax, %ecx
movl $0x3e8, %eax            # imm = 0x3E8
cltd
idivl %ecx
movl %eax, %ecx
movl -0x4c(%rbp), %eax
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x19c61
callq 0x3aa40
movl $0x3e8, %eax            # imm = 0x3E8
cltd
idivl 0xa549b(%rip)           # 0xbf108
movl %eax, %ecx
movl $0x3e8, %eax            # imm = 0x3E8
cmpl %ecx, %eax
jle 0x19ca4
movl 0xa54c6(%rip), %eax     # 0xbf144
movl %eax, -0x50(%rbp)
movl $0x3e8, %eax            # imm = 0x3E8
cltd
idivl 0xa547b(%rip)           # 0xbf108
movl %eax, %ecx
movl $0x3e8, %eax            # imm = 0x3E8
cltd
idivl %ecx
movl %eax, %ecx
movl -0x50(%rbp), %eax
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x19ca9
callq 0x3ad10
cmpl $-0x1, 0xa5ae8(%rip)    # 0xbf798
je 0x19d70
leaq -0x20(%rbp), %rdi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x12210
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
je 0x19d6b
movl -0x20(%rbp), %eax
andl $0xff00, %eax           # imm = 0xFF00
sarl $0x8, %eax
movl %eax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x20(%rbp), %eax
andl $0x7f, %eax
addl $0x1, %eax
movsbl %al, %eax
sarl %eax
cmpl $0x0, %eax
jle 0x19d05
movl -0x20(%rbp), %eax
andl $0x7f, %eax
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x24(%rbp)
jne 0x19d35
callq 0x120b0
movl (%rax), %edi
callq 0x12900
movq %rax, %rdx
movl 0xa5a78(%rip), %ecx     # 0xbf798
movl $0x3, %edi
leaq 0x8990b(%rip), %rsi     # 0xa3637
movb $0x0, %al
callq 0x18b10
jmp 0x19d66
movl -0x24(%rbp), %eax
cmpl 0xa5a5a(%rip), %eax     # 0xbf798
jne 0x19d4d
movl -0x28(%rbp), %edi
movl -0x2c(%rbp), %esi
callq 0x3caa0
jmp 0x19d64
movslq -0x24(%rbp), %rdx
movl $0x3, %edi
leaq 0x8990c(%rip), %rsi     # 0xa3669
movb $0x0, %al
callq 0x18b10
jmp 0x19d66
callq 0x19460
jmp 0x19e27
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl 0xa5a28(%rip), %eax     # 0xbf7a8
jge 0x19e25
movq 0xa5a13(%rip), %rax     # 0xbf7a0
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq 0xa59e5(%rip), %rax     # 0xbf788
movq -0x38(%rbp), %rcx
movslq 0x8(%rcx), %rcx
cmpq %rcx, %rax
jl 0x19e15
movq 0xa5979(%rip), %rax     # 0xbf730
subq 0xa5a02(%rip), %rax     # 0xbf7c0
movq -0x38(%rbp), %rcx
cmpq (%rcx), %rax
jle 0x19e15
movq 0xa5962(%rip), %rax     # 0xbf730
subq 0xa59f3(%rip), %rax     # 0xbf7c8
cmpq $0x5, %rax
jg 0x19de4
cmpl $0x0, 0xa5a02(%rip)     # 0xbf7e4
jne 0x19e15
movq 0xa599d(%rip), %rdx     # 0xbf788
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl %eax, %ecx
movl $0x2, %edi
leaq 0x89899(%rip), %rsi     # 0xa3699
movb $0x0, %al
callq 0x18b10
movq 0xa59a2(%rip), %rdi     # 0xbf7b0
callq 0x3bf00
jmp 0x19e25
jmp 0x19e17
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x19d77
jmp 0x19e27
callq 0x25560
callq 0x26490
movl $0x3e8, %eax            # imm = 0x3E8
cltd
idivl 0xa52cb(%rip)           # 0xbf108
movl %eax, %ecx
movl $0x64, %eax
cmpl %ecx, %eax
jle 0x19e74
movl 0xa52f6(%rip), %eax     # 0xbf144
movl %eax, -0x54(%rbp)
movl $0x3e8, %eax            # imm = 0x3E8
cltd
idivl 0xa52ab(%rip)           # 0xbf108
movl %eax, %ecx
movl $0x64, %eax
cltd
idivl %ecx
movl %eax, %ecx
movl -0x54(%rbp), %eax
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x19e79
callq 0x34b40
movl 0xa52c5(%rip), %eax     # 0xbf144
addl $0x1, %eax
movl %eax, 0xa52bc(%rip)     # 0xbf144
movl $0x3e8, %eax            # imm = 0x3E8
cltd
idivl 0xa5274(%rip)           # 0xbf108
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)