// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movl 0x14603e(%rip), %eax    # 0x178adc
addl $0x20, %eax
movl %eax, %eax
movq %rax, -0x8(%rbp)
movl $0x7, %edi
leaq -0x18(%rbp), %rsi
callq 0x26840
cmpl $-0x1, %eax
jne 0x32aeb
callq 0x26880
movl (%rax), %edi
callq 0x26690
movq %rax, %rdx
movl $0x3, %edi
leaq 0x1055ac(%rip), %rsi    # 0x138081
movb $0x0, %al
callq 0x2fc60
movl $0x3e0, 0x145ff6(%rip)  # imm = 0x3E0
jmp 0x32c55
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x8(%rbp), %rax
jae 0x32c53
movl $0x0, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
jbe 0x32b6e
movq $0x10, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x10(%rbp)
movl $0x7, %edi
leaq -0x18(%rbp), %rsi
callq 0x26530
cmpl $-0x1, %eax
je 0x32b47
jmp 0x32b6e
callq 0x26880
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x32b5d
jmp 0x32b6e
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x28(%rbp)
jmp 0x32b10
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x32b80
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x8(%rbp), %rax
jae 0x32c36
movl 0x145f48(%rip), %eax    # 0x178adc
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rax
subq $0x20, %rax
movl %eax, 0x145f37(%rip)    # 0x178adc
cmpl $0x1, 0x145f30(%rip)    # 0x178adc
jae 0x32bd3
movq -0x20(%rbp), %rdx
movq -0x8(%rbp), %rcx
movl $0x3, %edi
leaq 0x105534(%rip), %rsi    # 0x1380f6
movb $0x0, %al
callq 0x2fc60
movl $0x1, %edi
callq 0x262d0
movl -0x3c(%rbp), %edx
movq -0x8(%rbp), %rcx
movl $0x3, %edi
leaq 0x105598(%rip), %rsi    # 0x13817e
movb $0x0, %al
callq 0x2fc60
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x2c(%rbp), %edi
callq 0x26690
movq -0x48(%rbp), %rdx
movq %rax, %rcx
movl $0x3, %edi
leaq 0x1055bb(%rip), %rsi    # 0x1381cb
movb $0x0, %al
callq 0x2fc60
movq -0x28(%rbp), %rdx
movl 0x145ebb(%rip), %ecx    # 0x178adc
movl $0x3, %edi
leaq 0x1055e3(%rip), %rsi    # 0x138210
movb $0x0, %al
callq 0x2fc60
jmp 0x32c51
movq -0x8(%rbp), %rdx
movq -0x20(%rbp), %rcx
movl $0x2, %edi
leaq 0x10565e(%rip), %rsi    # 0x1382a8
movb $0x0, %al
callq 0x2fc60
jmp 0x32c53
jmp 0x32c55
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)