// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/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: flush buffers and fsync() the AOF at exit */
        serverLog(LL_NOTICE,"Calling fsync() on the AOF file.");
        flushAppendOnlyFile(1);
        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 0x80796(%rip), %rsi     # 0xaf635
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
callq 0x65133
cmpl $-0x1, 0xcb123(%rip)    # 0xf9fd8
je 0x2eee1
leaq 0x80792(%rip), %rsi     # 0xaf650
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
movl 0xcb10a(%rip), %edi     # 0xf9fd8
pushq $0xa
popq %rsi
callq 0x26660
movl 0xcb0fc(%rip), %edi     # 0xf9fd8
callq 0x41d27
movl 0xcb029(%rip), %eax     # 0xf9f10
testl %eax, %eax
je 0x2ef48
cmpl $-0x1, 0xcb052(%rip)    # 0xf9f44
je 0x2ef24
cmpl $0x2, %eax
jne 0x2ef05
leaq 0x8077d(%rip), %rsi     # 0xaf67d
jmp 0x2ef89
leaq 0x80792(%rip), %rsi     # 0xaf69e
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
movl 0xcb028(%rip), %edi     # 0xf9f44
pushq $0xa
popq %rsi
callq 0x26660
leaq 0x807a3(%rip), %rsi     # 0xaf6ce
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x2b699
pushq $0x1
popq %rdi
callq 0x53b99
movl 0xcb015(%rip), %edi     # 0xf9f58
callq 0x26570
cmpl $0x0, 0xcb099(%rip)     # 0xf9fe8
setg %al
testb $0x2, %bl
sete %cl
testb $0x1, %bl
jne 0x2ef61
andb %al, %cl
je 0x2ef98
leaq 0x80787(%rip), %rsi     # 0xaf6ef
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x2b699
movq 0xcb077(%rip), %rdi     # 0xf9ff0
callq 0x41971
testl %eax, %eax
je 0x2ef98
leaq 0x80794(%rip), %rsi     # 0xaf71d
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
pushq $-0x1
popq %rbx
jmp 0x2f001
cmpl $0x0, 0xcaf25(%rip)     # 0xf9ec4
jne 0x2efab
cmpq $0x0, 0xca95f(%rip)     # 0xf9908
je 0x2efc8
leaq 0x80794(%rip), %rsi     # 0xaf746
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x2b699
movq 0xca945(%rip), %rdi     # 0xf9908
callq 0x263b0
callq 0x391d7
pushq $0x1
popq %rdi
callq 0x2edf6
cmpl $0x0, 0xca968(%rip)     # 0xf9944
leaq 0x807a7(%rip), %rax     # 0xaf78a
leaq 0x80797(%rip), %rdx     # 0xaf781
cmoveq %rax, %rdx
leaq 0x80768(%rip), %rsi     # 0xaf75d
xorl %ebx, %ebx
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
movl %ebx, %eax
popq %rbx
retq