// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/server.c
// Function: prepareForShutdown
int prepareForShutdown(int flags) {
    int save = flags & SHUTDOWN_SAVE;
    int nosave = flags & SHUTDOWN_NOSAVE;

    serverLog(LL_WARNING,"User requested shutdown...");

    /* Kill all the Lua debugger forked sessions. */
    ldbKillForkedSessions();

    /* Kill the saving child if there is a background saving in progress.
       We want to avoid race conditions, for instance our saving child may
       overwrite the synchronous saving did by SHUTDOWN. */
    if (server.rdb_child_pid != -1) {
        serverLog(LL_WARNING,"There is a child saving an .rdb. Killing it!");
        kill(server.rdb_child_pid,SIGUSR1);
        rdbRemoveTempFile(server.rdb_child_pid);
    }

    if (server.aof_state != AOF_OFF) {
        /* Kill the AOF saving child as the AOF we already have may be longer
         * but contains the full dataset anyway. */
        if (server.aof_child_pid != -1) {
            /* If we have AOF enabled but haven't written the AOF yet, don't
             * shutdown or else the dataset will be lost. */
            if (server.aof_state == AOF_WAIT_REWRITE) {
                serverLog(LL_WARNING, "Writing initial AOF, can't exit.");
                return C_ERR;
            }
            serverLog(LL_WARNING,
                "There is a child rewriting the AOF. Killing it!");
            kill(server.aof_child_pid,SIGUSR1);
        }
        /* Append only file: fsync() the AOF and exit */
        serverLog(LL_NOTICE,"Calling fsync() on the AOF file.");
        aof_fsync(server.aof_fd);
    }

    /* Create a new RDB file before exiting. */
    if ((server.saveparamslen > 0 && !nosave) || save) {
        serverLog(LL_NOTICE,"Saving the final RDB snapshot before exiting.");
        /* Snapshotting. Perform a SYNC SAVE and exit */
        if (rdbSave(server.rdb_filename) != C_OK) {
            /* Ooops.. error saving! The best we can do is to continue
             * operating. Note that if there was a background saving process,
             * in the next cron() Redis will be notified that the background
             * saving aborted, handling special stuff like slaves pending for
             * synchronization... */
            serverLog(LL_WARNING,"Error trying to save the DB, can't exit.");
            return C_ERR;
        }
    }

    /* Remove the pid file if possible and needed. */
    if (server.daemonize || server.pidfile) {
        serverLog(LL_NOTICE,"Removing the pid file.");
        unlink(server.pidfile);
    }

    /* Best effort flush of slave output buffers, so that we hopefully
     * send them pending writes. */
    flushSlavesOutputBuffers();

    /* Close the listening sockets. Apparently this allows faster restarts. */
    closeListeningSockets(1);
    serverLog(LL_WARNING,"%s is now ready to exit, bye bye...",
        server.sentinel_mode ? "Sentinel" : "Redis");
    return C_OK;
}

// Assembly:
pushq %rbx
movl %edi, %ebx
leaq 0x89982(%rip), %rsi     # 0xc06d3
movl $0x3, %edi
xorl %eax, %eax
callq 0x32ea6
callq 0x7430b
cmpl $-0x1, 0xd020f(%rip)    # 0x106f78
je 0x36d99
leaq 0x8997c(%rip), %rsi     # 0xc06ee
movl $0x3, %edi
xorl %eax, %eax
callq 0x32ea6
movl 0xd01f4(%rip), %edi     # 0x106f78
movl $0xa, %esi
callq 0x26670
movl 0xd01e4(%rip), %edi     # 0x106f78
callq 0x4cf82
movl 0xd0111(%rip), %eax     # 0x106eb0
testl %eax, %eax
je 0x36dfe
cmpl $-0x1, 0xd013a(%rip)    # 0x106ee4
je 0x36de0
cmpl $0x2, %eax
jne 0x36dbd
leaq 0x89963(%rip), %rsi     # 0xc071b
jmp 0x36e41
leaq 0x89978(%rip), %rsi     # 0xc073c
movl $0x3, %edi
xorl %eax, %eax
callq 0x32ea6
movl 0xd010e(%rip), %edi     # 0x106ee4
movl $0xa, %esi
callq 0x26670
leaq 0x89985(%rip), %rsi     # 0xc076c
movl $0x2, %edi
xorl %eax, %eax
callq 0x32ea6
movl 0xd00ff(%rip), %edi     # 0x106ef8
callq 0x26580
cmpl $0x0, 0xd0183(%rip)     # 0x106f88
setg %al
testb $0x2, %bl
sete %cl
testb $0x1, %bl
jne 0x36e17
andb %al, %cl
je 0x36e54
leaq 0x8996f(%rip), %rsi     # 0xc078d
movl $0x2, %edi
xorl %eax, %eax
callq 0x32ea6
movq 0xd015f(%rip), %rdi     # 0x106f90
callq 0x4cb97
testl %eax, %eax
je 0x36e54
leaq 0x8997a(%rip), %rsi     # 0xc07bb
movl $0x3, %edi
xorl %eax, %eax
callq 0x32ea6
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x36ec3
cmpl $0x0, 0xd0009(%rip)     # 0x106e64
jne 0x36e67
cmpq $0x0, 0xcfa53(%rip)     # 0x1068b8
je 0x36e86
leaq 0x89976(%rip), %rsi     # 0xc07e4
movl $0x2, %edi
xorl %eax, %eax
callq 0x32ea6
movq 0xcfa37(%rip), %rdi     # 0x1068b8
callq 0x263c0
callq 0x42da9
movl $0x1, %edi
callq 0x36c98
cmpl $0x0, 0xcfa58(%rip)     # 0x1068f4
leaq 0x89985(%rip), %rax     # 0xc0828
leaq 0x89975(%rip), %rdx     # 0xc081f
cmoveq %rax, %rdx
leaq 0x89946(%rip), %rsi     # 0xc07fb
xorl %ebx, %ebx
movl $0x3, %edi
xorl %eax, %eax
callq 0x32ea6
movl %ebx, %eax
popq %rbx
retq