// File: /workspace/github_c_makefile_star2_O3/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 0x89a62(%rip), %rsi     # 0xbd745
movl $0x3, %edi
xorl %eax, %eax
callq 0x2fdad
callq 0x708a0
cmpl $-0x1, 0xce2dd(%rip)    # 0x101fd8
je 0x33d2b
leaq 0x89a5c(%rip), %rsi     # 0xbd760
movl $0x3, %edi
xorl %eax, %eax
callq 0x2fdad
movl 0xce2c2(%rip), %edi     # 0x101fd8
movl $0xa, %esi
callq 0x26660
movl 0xce2b2(%rip), %edi     # 0x101fd8
callq 0x4997e
movl 0xce1df(%rip), %eax     # 0x101f10
testl %eax, %eax
je 0x33d9a
cmpl $-0x1, 0xce208(%rip)    # 0x101f44
je 0x33d72
cmpl $0x2, %eax
jne 0x33d4f
leaq 0x89a43(%rip), %rsi     # 0xbd78d
jmp 0x33ddd
leaq 0x89a58(%rip), %rsi     # 0xbd7ae
movl $0x3, %edi
xorl %eax, %eax
callq 0x2fdad
movl 0xce1dc(%rip), %edi     # 0x101f44
movl $0xa, %esi
callq 0x26660
leaq 0x89a65(%rip), %rsi     # 0xbd7de
movl $0x2, %edi
xorl %eax, %eax
callq 0x2fdad
movl $0x1, %edi
callq 0x5d159
movl 0xce1c3(%rip), %edi     # 0x101f58
callq 0x26570
cmpl $0x0, 0xce247(%rip)     # 0x101fe8
setg %al
testb $0x2, %bl
sete %cl
testb $0x1, %bl
jne 0x33db3
andb %al, %cl
je 0x33df0
leaq 0x89a45(%rip), %rsi     # 0xbd7ff
movl $0x2, %edi
xorl %eax, %eax
callq 0x2fdad
movq 0xce223(%rip), %rdi     # 0x101ff0
callq 0x49593
testl %eax, %eax
je 0x33df0
leaq 0x89a50(%rip), %rsi     # 0xbd82d
movl $0x3, %edi
xorl %eax, %eax
callq 0x2fdad
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x33e5f
cmpl $0x0, 0xce0cd(%rip)     # 0x101ec4
jne 0x33e03
cmpq $0x0, 0xcdb07(%rip)     # 0x101908
je 0x33e22
leaq 0x89a4c(%rip), %rsi     # 0xbd856
movl $0x2, %edi
xorl %eax, %eax
callq 0x2fdad
movq 0xcdaeb(%rip), %rdi     # 0x101908
callq 0x263b0
callq 0x3f95d
movl $0x1, %edi
callq 0x33c2a
cmpl $0x0, 0xcdb0c(%rip)     # 0x101944
leaq 0x89a5b(%rip), %rax     # 0xbd89a
leaq 0x89a4b(%rip), %rdx     # 0xbd891
cmoveq %rax, %rdx
leaq 0x89a1c(%rip), %rsi     # 0xbd86d
xorl %ebx, %ebx
movl $0x3, %edi
xorl %eax, %eax
callq 0x2fdad
movl %ebx, %eax
popq %rbx
retq