// File: /workspace/github_c_makefile_star2_O2/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 0xccb75(%rip), %ebx     # 0xfa1ac
pushq $0x7
popq %rdi
leaq 0x8(%rsp), %rsi
callq 0x26840
cmpl $-0x1, %eax
je 0x2d71c
addl $0x20, %ebx
movq 0x8(%rsp), %r15
cmpq %rbx, %r15
jae 0x2d75f
xorl %ebp, %ebp
pushq $0x7
popq %r12
leaq 0x8(%rsp), %r13
movq %rbx, %rax
movq %rax, %r14
cmpq %r15, %rax
jbe 0x2d6a2
movq %r14, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movl %r12d, %edi
movq %r13, %rsi
callq 0x26540
cmpl $-0x1, %eax
jne 0x2d6a2
callq 0x26880
movl (%rax), %ebp
leaq -0x10(%r14), %rax
movq %rax, %rcx
addq $0x10, %rcx
jae 0x2d66c
cmpq %r15, %r14
cmovbeq %r15, %r14
cmpq %rbx, %r14
jae 0x2d748
movl 0xccaf4(%rip), %edx     # 0xfa1ac
movl %r14d, %eax
addl $-0x20, %eax
movl %eax, 0xccae8(%rip)     # 0xfa1ac
je 0x2d76e
leaq 0x81a2d(%rip), %rsi     # 0xaf0fe
pushq $0x3
popq %r15
movl %r15d, %edi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2b699
movl %ebp, %edi
callq 0x26680
leaq 0x81a5b(%rip), %rsi     # 0xaf14b
movl %r15d, %edi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2b699
movl 0xccaa6(%rip), %ecx     # 0xfa1ac
leaq 0x81a83(%rip), %rsi     # 0xaf190
movl %r15d, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2b699
jmp 0x2d75f
callq 0x26880
movl (%rax), %edi
callq 0x26680
leaq 0x818d2(%rip), %rsi     # 0xaf001
pushq $0x3
popq %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2b699
movl $0x3e0, 0xcca66(%rip)   # imm = 0x3E0
jmp 0x2d75f
leaq 0x81ad9(%rip), %rsi     # 0xaf228
pushq $0x2
popq %rdi
movq %rbx, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x2b699
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x81901(%rip), %rsi     # 0xaf076
pushq $0x3
popq %rdi
movq %r15, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2b699
pushq $0x1
popq %rdi
callq 0x262c0