// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/src/server.c
// Function: adjustOpenFilesLimit
void adjustOpenFilesLimit(void) {
    rlim_t maxfiles = server.maxclients+CONFIG_MIN_RESERVED_FDS;
    struct rlimit limit;

    if (getrlimit(RLIMIT_NOFILE,&limit) == -1) {
        serverLog(LL_WARNING,"Unable to obtain the current NOFILE limit (%s), assuming 1024 and setting the max clients configuration accordingly.",
            strerror(errno));
        server.maxclients = 1024-CONFIG_MIN_RESERVED_FDS;
    } else {
        rlim_t oldlimit = limit.rlim_cur;

        /* Set the max number of files if the current limit is not enough
         * for our needs. */
        if (oldlimit < maxfiles) {
            rlim_t bestlimit;
            int setrlimit_error = 0;

            /* Try to set the file limit to match 'maxfiles' or at least
             * to the higher value supported less than maxfiles. */
            bestlimit = maxfiles;
            while(bestlimit > oldlimit) {
                rlim_t decr_step = 16;

                limit.rlim_cur = bestlimit;
                limit.rlim_max = bestlimit;
                if (setrlimit(RLIMIT_NOFILE,&limit) != -1) break;
                setrlimit_error = errno;

                /* We failed to set file limit to 'bestlimit'. Try with a
                 * smaller limit decrementing by a few FDs per iteration. */
                if (bestlimit < decr_step) break;
                bestlimit -= decr_step;
            }

            /* Assume that the limit we get initially is still valid if
             * our last try was even lower. */
            if (bestlimit < oldlimit) bestlimit = oldlimit;

            if (bestlimit < maxfiles) {
                int old_maxclients = server.maxclients;
                server.maxclients = bestlimit-CONFIG_MIN_RESERVED_FDS;
                if (server.maxclients < 1) {
                    serverLog(LL_WARNING,"Your current 'ulimit -n' "
                        "of %llu is not enough for the server to start. "
                        "Please increase your open file limit to at least "
                        "%llu. Exiting.",
                        (unsigned long long) oldlimit,
                        (unsigned long long) maxfiles);
                    exit(1);
                }
                serverLog(LL_WARNING,"You requested maxclients of %d "
                    "requiring at least %llu max file descriptors.",
                    old_maxclients,
                    (unsigned long long) maxfiles);
                serverLog(LL_WARNING,"Server can't set maximum open files "
                    "to %llu because of OS error: %s.",
                    (unsigned long long) maxfiles, strerror(setrlimit_error));
                serverLog(LL_WARNING,"Current maximum open files is %llu. "
                    "maxclients has been reduced to %d to compensate for "
                    "low ulimit. "
                    "If you need higher maxclients increase 'ulimit -n'.",
                    (unsigned long long) bestlimit, server.maxclients);
            } else {
                serverLog(LL_NOTICE,"Increased maximum number of open files "
                    "to %llu (it was originally set to %llu).",
                    (unsigned long long) maxfiles,
                    (unsigned long long) oldlimit);
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0xd0013(%rip), %ebx     # 0x1021ac
leaq 0x8(%rsp), %rsi
movl $0x7, %edi
callq 0x26840
cmpl $-0x1, %eax
je 0x32262
addl $0x20, %ebx
movq 0x8(%rsp), %r14
cmpq %rbx, %r14
jae 0x322a9
leaq 0x8(%rsp), %rsi
movq %rbx, (%rsi)
movq %rbx, 0x8(%rsi)
movl $0x7, %edi
callq 0x26540
xorl %ebp, %ebp
movq %rbx, %r15
cmpl $-0x1, %eax
je 0x322b8
cmpq %r14, %r15
cmovbeq %r14, %r15
cmpq %rbx, %r15
jae 0x32290
movl 0xcffb0(%rip), %edx     # 0x1021ac
movl %r15d, %eax
addl $-0x20, %eax
movl %eax, 0xcffa4(%rip)     # 0x1021ac
je 0x32304
leaq 0x8aff9(%rip), %rsi     # 0xbd20e
movl $0x3, %edi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2fdad
movl %ebp, %edi
callq 0x26680
leaq 0x8b029(%rip), %rsi     # 0xbd25b
movl $0x3, %edi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2fdad
movl 0xcff62(%rip), %ecx     # 0x1021ac
leaq 0x8b04f(%rip), %rsi     # 0xbd2a0
movl $0x3, %edi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2fdad
jmp 0x322a9
callq 0x26880
movl (%rax), %edi
callq 0x26680
leaq 0x8ae9c(%rip), %rsi     # 0xbd111
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2fdad
movl $0x3e0, 0xcff1e(%rip)   # imm = 0x3E0
jmp 0x322a9
leaq 0x8b0a1(%rip), %rsi     # 0xbd338
movl $0x2, %edi
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x2fdad
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x26880
movq %rax, %r12
leaq 0x8(%rsp), %r13
movq %rbx, %r15
movl (%r12), %ebp
cmpq $0x10, %r15
jb 0x321e6
addq $-0x10, %r15
cmpq %r14, %r15
jbe 0x321e6
movq %r15, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movl $0x7, %edi
movq %r13, %rsi
callq 0x26540
cmpl $-0x1, %eax
je 0x322c8
jmp 0x321e6
leaq 0x8ae7b(%rip), %rsi     # 0xbd186
movl $0x3, %edi
movq %r14, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2fdad
movl $0x1, %edi
callq 0x262c0