// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl %edi, -0x8(%rbp)
movl -0x8(%rbp), %eax
andl $0x1, %eax
movl %eax, -0xc(%rbp)
movl -0x8(%rbp), %eax
andl $0x2, %eax
movl %eax, -0x10(%rbp)
movl $0x3, %edi
leaq 0x10367c(%rip), %rsi    # 0x1386b5
movb $0x0, %al
callq 0x2fc60
callq 0x8c310
cmpl $-0x1, 0x1438bc(%rip)   # 0x178908
je 0x3507c
movl $0x3, %edi
leaq 0x103676(%rip), %rsi    # 0x1386d0
movb $0x0, %al
callq 0x2fc60
movl 0x1438a1(%rip), %edi    # 0x178908
movl $0xa, %esi
callq 0x26670
movl 0x143891(%rip), %edi    # 0x178908
callq 0x555f0
cmpl $0x0, 0x1437bd(%rip)    # 0x178840
je 0x35101
cmpl $-0x1, 0x1437e8(%rip)   # 0x178874
je 0x350d9
cmpl $0x2, 0x1437ab(%rip)    # 0x178840
jne 0x350b6
movl $0x3, %edi
leaq 0x10365a(%rip), %rsi    # 0x1386fd
movb $0x0, %al
callq 0x2fc60
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x351ce
movl $0x3, %edi
leaq 0x10365c(%rip), %rsi    # 0x13871e
movb $0x0, %al
callq 0x2fc60
movl 0x1437a5(%rip), %edi    # 0x178874
movl $0xa, %esi
callq 0x26670
movl $0x2, %edi
leaq 0x103669(%rip), %rsi    # 0x13874e
movb $0x0, %al
callq 0x2fc60
movl $0x1, %edi
callq 0x70c00
movl 0x14378c(%rip), %edi    # 0x178888
callq 0x26560
cmpl $0x0, 0x143810(%rip)    # 0x178918
jle 0x35110
cmpl $0x0, -0x10(%rbp)
je 0x35116
cmpl $0x0, -0xc(%rbp)
je 0x35158
movl $0x2, %edi
leaq 0x10364d(%rip), %rsi    # 0x13876f
movb $0x0, %al
callq 0x2fc60
movq 0x1437f0(%rip), %rdi    # 0x178920
callq 0x55050
cmpl $0x0, %eax
je 0x35156
movl $0x3, %edi
leaq 0x103657(%rip), %rsi    # 0x13879d
movb $0x0, %al
callq 0x2fc60
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x351ce
jmp 0x35158
cmpl $0x0, 0x143695(%rip)    # 0x1787f4
jne 0x3516b
cmpq $0x0, 0x1430cf(%rip)    # 0x178238
je 0x3518a
movl $0x2, %edi
leaq 0x10364f(%rip), %rsi    # 0x1387c6
movb $0x0, %al
callq 0x2fc60
movq 0x1430b3(%rip), %rdi    # 0x178238
callq 0x263b0
callq 0x46de0
movl $0x1, %edi
callq 0x34f40
movl 0x1430d5(%rip), %ecx    # 0x178274
leaq 0x103664(%rip), %rdx    # 0x13880a
leaq 0x103654(%rip), %rax    # 0x138801
cmpl $0x0, %ecx
cmovneq %rax, %rdx
movl $0x3, %edi
leaq 0x10361d(%rip), %rsi    # 0x1387dd
movb $0x0, %al
callq 0x2fc60
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x10, %rsp
popq %rbp
retq
nopw (%rax,%rax)