// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/replication.c
// Function: replicationCron
void replicationCron(void) {
    static long long replication_cron_loops = 0;

    /* Non blocking connection timeout? */
    if (server.masterhost &&
        (server.repl_state == REPL_STATE_CONNECTING ||
         slaveIsInHandshakeState()) &&
         (time(NULL)-server.repl_transfer_lastio) > server.repl_timeout)
    {
        serverLog(LL_WARNING,"Timeout connecting to the MASTER...");
        cancelReplicationHandshake();
    }

    /* Bulk transfer I/O timeout? */
    if (server.masterhost && server.repl_state == REPL_STATE_TRANSFER &&
        (time(NULL)-server.repl_transfer_lastio) > server.repl_timeout)
    {
        serverLog(LL_WARNING,"Timeout receiving bulk data from MASTER... If the problem persists try to set the 'repl-timeout' parameter in redis.conf to a larger value.");
        cancelReplicationHandshake();
    }

    /* Timed out master when we are an already connected slave? */
    if (server.masterhost && server.repl_state == REPL_STATE_CONNECTED &&
        (time(NULL)-server.master->lastinteraction) > server.repl_timeout)
    {
        serverLog(LL_WARNING,"MASTER timeout: no data nor PING received...");
        freeClient(server.master);
    }

    /* Check if we should connect to a MASTER */
    if (server.repl_state == REPL_STATE_CONNECT) {
        serverLog(LL_NOTICE,"Connecting to MASTER %s:%d",
            server.masterhost, server.masterport);
        if (connectWithMaster() == C_OK) {
            serverLog(LL_NOTICE,"MASTER <-> SLAVE sync started");
        }
    }

    /* Send ACK to master from time to time.
     * Note that we do not send periodic acks to masters that don't
     * support PSYNC and replication offsets. */
    if (server.masterhost && server.master &&
        !(server.master->flags & CLIENT_PRE_PSYNC))
        replicationSendAck();

    /* If we have attached slaves, PING them from time to time.
     * So slaves can implement an explicit timeout to masters, and will
     * be able to detect a link disconnection even if the TCP connection
     * will not actually go down. */
    listIter li;
    listNode *ln;
    robj *ping_argv[1];

    /* First, send PING according to ping_slave_period. */
    if ((replication_cron_loops % server.repl_ping_slave_period) == 0) {
        ping_argv[0] = createStringObject("PING",4);
        replicationFeedSlaves(server.slaves, server.slaveseldb,
            ping_argv, 1);
        decrRefCount(ping_argv[0]);
    }

    /* Second, send a newline to all the slaves in pre-synchronization
     * stage, that is, slaves waiting for the master to create the RDB file.
     * The newline will be ignored by the slave but will refresh the
     * last-io timer preventing a timeout. In this case we ignore the
     * ping period and refresh the connection once per second since certain
     * timeouts are set at a few seconds (example: PSYNC response). */
    listRewind(server.slaves,&li);
    while((ln = listNext(&li))) {
        client *slave = ln->value;

        if (slave->replstate == SLAVE_STATE_WAIT_BGSAVE_START ||
            (slave->replstate == SLAVE_STATE_WAIT_BGSAVE_END &&
             server.rdb_child_type != RDB_CHILD_TYPE_SOCKET))
        {
            if (write(slave->fd, "\n", 1) == -1) {
                /* Don't worry, it's just a ping. */
            }
        }
    }

    /* Disconnect timedout slaves. */
    if (listLength(server.slaves)) {
        listIter li;
        listNode *ln;

        listRewind(server.slaves,&li);
        while((ln = listNext(&li))) {
            client *slave = ln->value;

            if (slave->replstate != SLAVE_STATE_ONLINE) continue;
            if (slave->flags & CLIENT_PRE_PSYNC) continue;
            if ((server.unixtime - slave->repl_ack_time) > server.repl_timeout)
            {
                serverLog(LL_WARNING, "Disconnecting timedout slave: %s",
                    replicationGetSlaveName(slave));
                freeClient(slave);
            }
        }
    }

    /* If we have no attached slaves and there is a replication backlog
     * using memory, free it after some (configured) time. */
    if (listLength(server.slaves) == 0 && server.repl_backlog_time_limit &&
        server.repl_backlog)
    {
        time_t idle = server.unixtime - server.repl_no_slaves_since;

        if (idle > server.repl_backlog_time_limit) {
            freeReplicationBacklog();
            serverLog(LL_NOTICE,
                "Replication backlog freed after %d seconds "
                "without connected slaves.",
                (int) server.repl_backlog_time_limit);
        }
    }

    /* If AOF is disabled and we no longer have attached slaves, we can
     * free our Replication Script Cache as there is no need to propagate
     * EVALSHA at all. */
    if (listLength(server.slaves) == 0 &&
        server.aof_state == AOF_OFF &&
        listLength(server.repl_scriptcache_fifo) != 0)
    {
        replicationScriptCacheFlush();
    }

    /* Start a BGSAVE good for replication if we have slaves in
     * WAIT_BGSAVE_START state.
     *
     * In case of diskless replication, we make sure to wait the specified
     * number of seconds (according to configuration) so that other slaves
     * have the time to arrive before we start streaming. */
    if (server.rdb_child_pid == -1 && server.aof_child_pid == -1) {
        time_t idle, max_idle = 0;
        int slaves_waiting = 0;
        int mincapa = -1;
        listNode *ln;
        listIter li;

        listRewind(server.slaves,&li);
        while((ln = listNext(&li))) {
            client *slave = ln->value;
            if (slave->replstate == SLAVE_STATE_WAIT_BGSAVE_START) {
                idle = server.unixtime - slave->lastinteraction;
                if (idle > max_idle) max_idle = idle;
                slaves_waiting++;
                mincapa = (mincapa == -1) ? slave->slave_capa :
                                            (mincapa & slave->slave_capa);
            }
        }

        if (slaves_waiting &&
            (!server.repl_diskless_sync ||
             max_idle > server.repl_diskless_sync_delay))
        {
            /* Start the BGSAVE. The called function may start a
             * BGSAVE with socket target or disk target depending on the
             * configuration and slaves capabilities. */
            startBgsaveForReplication(mincapa);
        }
    }

    /* Refresh the number of slaves with lag <= min-slaves-max-lag. */
    refreshGoodSlavesCount();
    replication_cron_loops++; /* Incremented with frequency 1 HZ. */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
leaq 0x125d66(%rip), %rax    # 0x1781d8
cmpq $0x0, 0x828(%rax)
je 0x524d8
leaq 0x125d55(%rip), %rax    # 0x1781d8
cmpl $0x2, 0x84c(%rax)
je 0x52496
callq 0x4f900
cmpl $0x0, %eax
je 0x524d8
xorl %eax, %eax
movl %eax, %edi
callq 0x26ce0
leaq 0x125d32(%rip), %rcx    # 0x1781d8
subq 0x878(%rcx), %rax
leaq 0x125d24(%rip), %rcx    # 0x1781d8
movslq 0x834(%rcx), %rcx
cmpq %rcx, %rax
jle 0x524d8
movl $0x3, %edi
leaq 0xeaa60(%rip), %rsi     # 0x13cf2c
movb $0x0, %al
callq 0x2fc60
callq 0x50240
leaq 0x125cf9(%rip), %rax    # 0x1781d8
cmpq $0x0, 0x828(%rax)
je 0x5253b
leaq 0x125ce8(%rip), %rax    # 0x1781d8
cmpl $0xe, 0x84c(%rax)
jne 0x5253b
xorl %eax, %eax
movl %eax, %edi
callq 0x26ce0
leaq 0x125ccf(%rip), %rcx    # 0x1781d8
subq 0x878(%rcx), %rax
leaq 0x125cc1(%rip), %rcx    # 0x1781d8
movslq 0x834(%rcx), %rcx
cmpq %rcx, %rax
jle 0x5253b
movl $0x3, %edi
leaq 0xeaa21(%rip), %rsi     # 0x13cf50
movb $0x0, %al
callq 0x2fc60
callq 0x50240
leaq 0x125c96(%rip), %rax    # 0x1781d8
cmpq $0x0, 0x828(%rax)
je 0x525b3
leaq 0x125c85(%rip), %rax    # 0x1781d8
cmpl $0xf, 0x84c(%rax)
jne 0x525b3
xorl %eax, %eax
movl %eax, %edi
callq 0x26ce0
leaq 0x125c6c(%rip), %rcx    # 0x1781d8
movq 0x838(%rcx), %rcx
subq 0x88(%rcx), %rax
leaq 0x125c57(%rip), %rcx    # 0x1781d8
movslq 0x834(%rcx), %rcx
cmpq %rcx, %rax
jle 0x525b3
movl $0x3, %edi
leaq 0xeaa43(%rip), %rsi     # 0x13cfdc
movb $0x0, %al
callq 0x2fc60
leaq 0x125c31(%rip), %rax    # 0x1781d8
movq 0x838(%rax), %rdi
callq 0x43ea0
leaq 0x125c1e(%rip), %rax    # 0x1781d8
cmpl $0x1, 0x84c(%rax)
jne 0x52610
leaq 0x125c0e(%rip), %rax    # 0x1781d8
movq 0x828(%rax), %rdx
leaq 0x125c00(%rip), %rax    # 0x1781d8
movl 0x830(%rax), %ecx
movl $0x2, %edi
leaq 0xeaa1f(%rip), %rsi     # 0x13d009
movb $0x0, %al
callq 0x2fc60
callq 0x51580
cmpl $0x0, %eax
jne 0x5260e
movl $0x2, %edi
leaq 0xeaa1d(%rip), %rsi     # 0x13d024
movb $0x0, %al
callq 0x2fc60
jmp 0x52610
leaq 0x125bc1(%rip), %rax    # 0x1781d8
cmpq $0x0, 0x828(%rax)
je 0x52655
leaq 0x125bb0(%rip), %rax    # 0x1781d8
cmpq $0x0, 0x838(%rax)
je 0x52655
leaq 0x125b9f(%rip), %rax    # 0x1781d8
movq 0x838(%rax), %rax
movl 0x98(%rax), %eax
andl $0x10000, %eax          # imm = 0x10000
cmpl $0x0, %eax
jne 0x52655
callq 0x4f300
movq 0x13a4f4(%rip), %rax    # 0x18cb50
leaq 0x125b75(%rip), %rcx    # 0x1781d8
movslq 0x7c8(%rcx), %rcx
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x526bc
leaq 0xea2c1(%rip), %rdi     # 0x13c93d
movl $0x4, %esi
callq 0x486a0
movq %rax, -0x20(%rbp)
leaq 0x125b47(%rip), %rax    # 0x1781d8
movq 0x1e0(%rax), %rdi
leaq 0x125b39(%rip), %rax    # 0x1781d8
movl 0x7bc(%rax), %esi
leaq -0x20(%rbp), %rdx
movl $0x1, %ecx
callq 0x4dcc0
movq -0x20(%rbp), %rdi
callq 0x48f70
leaq 0x125b15(%rip), %rax    # 0x1781d8
movq 0x1e0(%rax), %rdi
leaq -0x10(%rbp), %rsi
callq 0x27320
leaq -0x10(%rbp), %rdi
callq 0x27380
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x52740
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x6, 0xa0(%rax)
je 0x5271c
movq -0x28(%rbp), %rax
cmpl $0x7, 0xa0(%rax)
jne 0x5273e
leaq 0x125ac5(%rip), %rax    # 0x1781d8
cmpl $0x2, 0x77c(%rax)
je 0x5273e
movq -0x28(%rbp), %rax
movl 0x8(%rax), %edi
leaq 0xe770f(%rip), %rsi     # 0x139e39
movl $0x1, %edx
callq 0x26bc0
cmpq $-0x1, %rax
jne 0x5273c
jmp 0x5273c
jmp 0x5273e
jmp 0x526d3
leaq 0x125a91(%rip), %rax    # 0x1781d8
movq 0x1e0(%rax), %rax
cmpq $0x0, 0x28(%rax)
je 0x52813
leaq 0x125a78(%rip), %rax    # 0x1781d8
movq 0x1e0(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x27320
leaq -0x38(%rbp), %rdi
callq 0x27380
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x52811
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpl $0x9, 0xa0(%rax)
je 0x527a2
jmp 0x52770
movq -0x48(%rbp), %rax
movl 0x98(%rax), %eax
andl $0x10000, %eax          # imm = 0x10000
cmpl $0x0, %eax
je 0x527b8
jmp 0x52770
leaq 0x125a19(%rip), %rax    # 0x1781d8
movq 0x978(%rax), %rax
movq -0x48(%rbp), %rcx
subq 0xd8(%rcx), %rax
leaq 0x125a00(%rip), %rcx    # 0x1781d8
movslq 0x834(%rcx), %rcx
cmpq %rcx, %rax
jle 0x5280c
movq -0x48(%rbp), %rdi
callq 0x4d700
movq %rax, %rdx
movl $0x3, %edi
leaq 0xea846(%rip), %rsi     # 0x13d042
movb $0x0, %al
callq 0x2fc60
movq -0x48(%rbp), %rdi
callq 0x43ea0
jmp 0x52770
jmp 0x52813
leaq 0x1259be(%rip), %rax    # 0x1781d8
movq 0x1e0(%rax), %rax
cmpq $0x0, 0x28(%rax)
jne 0x528ac
leaq 0x1259a5(%rip), %rax    # 0x1781d8
cmpq $0x0, 0x7f8(%rax)
je 0x528ac
leaq 0x125994(%rip), %rax    # 0x1781d8
cmpq $0x0, 0x7d0(%rax)
je 0x528ac
leaq 0x125983(%rip), %rax    # 0x1781d8
movq 0x978(%rax), %rax
leaq 0x125975(%rip), %rcx    # 0x1781d8
subq 0x800(%rcx), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
leaq 0x12595f(%rip), %rcx    # 0x1781d8
cmpq 0x7f8(%rcx), %rax
jle 0x528aa
callq 0x4d9a0
leaq 0x12594a(%rip), %rax    # 0x1781d8
movq 0x7f8(%rax), %rax
movl %eax, %edx
movl $0x2, %edi
leaq 0xea7c0(%rip), %rsi     # 0x13d063
movb $0x0, %al
callq 0x2fc60
jmp 0x528ac
leaq 0x125925(%rip), %rax    # 0x1781d8
movq 0x1e0(%rax), %rax
cmpq $0x0, 0x28(%rax)
jne 0x528eb
leaq 0x125910(%rip), %rax    # 0x1781d8
cmpl $0x0, 0x668(%rax)
jne 0x528eb
leaq 0x125900(%rip), %rax    # 0x1781d8
movq 0x8e8(%rax), %rax
cmpq $0x0, 0x28(%rax)
je 0x528eb
callq 0x4eaf0
leaq 0x1258e6(%rip), %rax    # 0x1781d8
cmpl $-0x1, 0x730(%rax)
jne 0x52a27
leaq 0x1258d2(%rip), %rax    # 0x1781d8
cmpl $-0x1, 0x69c(%rax)
jne 0x52a27
movq $0x0, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movl $0xffffffff, -0x68(%rbp) # imm = 0xFFFFFFFF
leaq 0x1258a8(%rip), %rax    # 0x1781d8
movq 0x1e0(%rax), %rdi
leaq -0x80(%rbp), %rsi
callq 0x27320
leaq -0x80(%rbp), %rdi
callq 0x27380
movq %rax, -0x70(%rbp)
cmpq $0x0, %rax
je 0x529f0
movq -0x70(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
cmpl $0x6, 0xa0(%rax)
jne 0x529eb
leaq 0x12585b(%rip), %rax    # 0x1781d8
movq 0x978(%rax), %rax
movq -0x88(%rbp), %rcx
subq 0x88(%rcx), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x60(%rbp), %rax
jle 0x529a8
movq -0x58(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
cmpl $-0x1, -0x68(%rbp)
jne 0x529cc
movq -0x88(%rbp), %rax
movl 0x148(%rax), %eax
movl %eax, -0x8c(%rbp)
jmp 0x529e2
movl -0x68(%rbp), %eax
movq -0x88(%rbp), %rcx
andl 0x148(%rcx), %eax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x68(%rbp)
jmp 0x52940
cmpl $0x0, -0x64(%rbp)
je 0x52a25
leaq 0x1257db(%rip), %rax    # 0x1781d8
cmpl $0x0, 0x814(%rax)
je 0x52a1d
movq -0x60(%rbp), %rax
leaq 0x1257c7(%rip), %rcx    # 0x1781d8
movslq 0x818(%rcx), %rcx
cmpq %rcx, %rax
jle 0x52a25
movl -0x68(%rbp), %edi
callq 0x4e920
jmp 0x52a27
callq 0x4e850
movq 0x13a11d(%rip), %rax    # 0x18cb50
addq $0x1, %rax
movq %rax, 0x13a112(%rip)    # 0x18cb50
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)