// File: /workspace/github_c_makefile_star2_O1/erikdubbelboer[P]discnt/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 Discnt 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,"Discnt 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 %r12
pushq %rbx
subq $0x10, %rsp
movl 0x53ef8(%rip), %ebx     # 0x6f694
movq %rsp, %rsi
movl $0x7, %edi
callq 0x12580
cmpl $-0x1, %eax
je 0x1b832
addl $0x20, %ebx
movq (%rsp), %r15
cmpq %rbx, %r15
jae 0x1b8c6
xorl %ebp, %ebp
movq %rsp, %r12
movq %rbx, %r14
cmpq %r15, %r14
jbe 0x1b808
movq %r14, (%rsp)
movq %r14, 0x8(%rsp)
movl $0x7, %edi
movq %r12, %rsi
callq 0x12330
cmpl $-0x1, %eax
je 0x1b7ee
xorl %eax, %eax
jmp 0x1b804
callq 0x120d0
movl (%rax), %ebp
leaq -0x10(%r14), %rcx
cmpq $0x10, %r14
setae %al
cmovaeq %rcx, %r14
testb %al, %al
jne 0x1b7ca
cmpq %r15, %r14
cmovbeq %r15, %r14
cmpq %rbx, %r14
jne 0x1b860
leaq 0x375a6(%rip), %rsi     # 0x52dc1
movl $0x2, %edi
movq %rbx, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x19fb1
jmp 0x1b8c6
callq 0x120d0
movl (%rax), %edi
callq 0x128f0
leaq 0x37359(%rip), %rsi     # 0x52b9e
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x19fb1
movl $0x3e0, 0x53e36(%rip)   # imm = 0x3E0
jmp 0x1b8c6
movl 0x53e2e(%rip), %edx     # 0x6f694
movl %r14d, %eax
addl $-0x20, %eax
movl %eax, 0x53e22(%rip)     # 0x6f694
je 0x1b8d3
leaq 0x3741c(%rip), %rsi     # 0x52c97
movl $0x3, %edi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x19fb1
movl %ebp, %edi
callq 0x128f0
leaq 0x3744c(%rip), %rsi     # 0x52ce4
movl $0x3, %edi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x19fb1
movl 0x53de4(%rip), %ecx     # 0x6f694
leaq 0x37472(%rip), %rsi     # 0x52d29
movl $0x3, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x19fb1
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x37339(%rip), %rsi     # 0x52c13
movl $0x3, %edi
movq %r15, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x19fb1
movl $0x1, %edi
callq 0x12870