// File: /workspace/github_c_makefile_star2_O1/nilyang[P]redis-tdd-annotation/src/redis.c
// Function: adjustOpenFilesLimit
void adjustOpenFilesLimit(void) {
    rlim_t maxfiles = server.maxclients+REDIS_MIN_RESERVED_FDS;
    struct rlimit limit;

    if (getrlimit(RLIMIT_NOFILE,&limit) == -1) {
        redisLog(REDIS_WARNING,"Unable to obtain the current NOFILE limit (%s), assuming 1024 and setting the max clients configuration accordingly.",
            strerror(errno));
        server.maxclients = 1024-REDIS_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 f;
            int setrlimit_error = 0;

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

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

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

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

            if (f != maxfiles) {
                int old_maxclients = server.maxclients;
                server.maxclients = f-REDIS_MIN_RESERVED_FDS;
                if (server.maxclients < 1) {
                    redisLog(REDIS_WARNING,"Your current 'ulimit -n' "
                        "of %llu is not enough for Redis to start. "
                        "Please increase your open file limit to at least "
                        "%llu. Exiting.",
                        (unsigned long long) oldlimit,
                        (unsigned long long) maxfiles);
                    exit(1);
                }
                redisLog(REDIS_WARNING,"You requested maxclients of %d "
                    "requiring at least %llu max file descriptors.",
                    old_maxclients,
                    (unsigned long long) maxfiles);
                redisLog(REDIS_WARNING,"Redis can't set maximum open files "
                    "to %llu because of OS error: %s.",
                    (unsigned long long) maxfiles, strerror(setrlimit_error));
                redisLog(REDIS_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) oldlimit, server.maxclients);
            } else {
                redisLog(REDIS_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
movslq 0xa5747(%rip), %rbx     # 0xca6c4
movq %rsp, %rsi
movl $0x7, %edi
callq 0x1f7e0
cmpl $-0x1, %eax
je 0x25015
addq $0x20, %rbx
movq (%rsp), %r14
cmpq %rbx, %r14
jae 0x250ab
xorl %ebp, %ebp
movq %rsp, %r15
movq %rbx, %r12
cmpq %r14, %r12
jbe 0x24feb
movq %r12, (%rsp)
movq %r12, 0x8(%rsp)
movl $0x7, %edi
movq %r15, %rsi
callq 0x1f530
cmpl $-0x1, %eax
je 0x24fd0
xorl %eax, %eax
jmp 0x24fe7
callq 0x1f810
movl (%rax), %ebp
leaq -0x10(%r12), %rcx
cmpq $0x10, %r12
setae %al
cmovaeq %rcx, %r12
testb %al, %al
jne 0x24fac
cmpq %r14, %r12
cmovbeq %r14, %r12
cmpq %rbx, %r12
jne 0x25043
leaq 0x6ff80(%rip), %rsi     # 0x94f7e
movl $0x2, %edi
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x23064
jmp 0x250ab
callq 0x1f810
movl (%rax), %edi
callq 0x1f630
leaq 0x6fd35(%rip), %rsi     # 0x94d5d
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x23064
movl $0x3e0, 0xa5683(%rip)   # imm = 0x3E0
jmp 0x250ab
movl 0xa567b(%rip), %edx     # 0xca6c4
addl $-0x20, %r12d
movl %r12d, 0xa5670(%rip)    # 0xca6c4
testl %r12d, %r12d
jle 0x250b8
leaq 0x6fdf5(%rip), %rsi     # 0x94e55
movl $0x3, %edi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x23064
movl %ebp, %edi
callq 0x1f630
leaq 0x6fe25(%rip), %rsi     # 0x94ea2
movl $0x3, %edi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x23064
movl 0xa562f(%rip), %ecx     # 0xca6c4
leaq 0x6fe4a(%rip), %rsi     # 0x94ee6
movl $0x3, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x23064
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6fd13(%rip), %rsi     # 0x94dd2
movl $0x3, %edi
movq %r14, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x23064
movl $0x1, %edi
callq 0x1f2b0