// File: /workspace/github_c_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movslq 0xa5565(%rip), %r12     # 0xca6c4
leaq 0x8(%rsp), %rsi
movl $0x7, %edi
callq 0x1f7e0
cmpl $-0x1, %eax
je 0x25215
addq $0x20, %r12
movq 0x8(%rsp), %r14
cmpq %r12, %r14
jae 0x252a8
leaq 0x8(%rsp), %rsi
movq %r12, (%rsi)
movq %r12, 0x8(%rsi)
movl $0x7, %edi
callq 0x1f530
xorl %ebp, %ebp
movq %r12, %rbx
cmpl $-0x1, %eax
jne 0x251eb
callq 0x1f810
movq %rax, %r15
movq %r12, %r13
movq %r13, %rbx
movl (%r15), %ebp
cmpq $0x10, %r13
jb 0x251eb
leaq -0x10(%rbx), %r13
cmpq %r14, %r13
jbe 0x251e7
movq %r13, 0x8(%rsp)
movq %r13, 0x10(%rsp)
movl $0x7, %edi
leaq 0x8(%rsp), %rsi
callq 0x1f530
cmpl $-0x1, %eax
je 0x251b4
addq $-0x10, %rbx
cmpq %r14, %rbx
cmovbeq %r14, %rbx
cmpq %r12, %rbx
jne 0x25243
leaq 0x6fdd0(%rip), %rsi     # 0x94fce
movl $0x2, %edi
movq %r12, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x23223
jmp 0x252a8
callq 0x1f810
movl (%rax), %edi
callq 0x1f630
leaq 0x6fb85(%rip), %rsi     # 0x94dad
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x23223
movl $0x3e0, 0xa5483(%rip)   # imm = 0x3E0
jmp 0x252a8
movl 0xa547b(%rip), %edx     # 0xca6c4
addl $-0x20, %ebx
movl %ebx, 0xa5472(%rip)     # 0xca6c4
testl %ebx, %ebx
jle 0x252b7
leaq 0x6fc48(%rip), %rsi     # 0x94ea5
movl $0x3, %edi
movq %r12, %rcx
xorl %eax, %eax
callq 0x23223
movl %ebp, %edi
callq 0x1f630
leaq 0x6fc78(%rip), %rsi     # 0x94ef2
movl $0x3, %edi
movq %r12, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x23223
movl 0xa5432(%rip), %ecx     # 0xca6c4
leaq 0x6fc9d(%rip), %rsi     # 0x94f36
movl $0x3, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x23223
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6fb64(%rip), %rsi     # 0x94e22
movl $0x3, %edi
movq %r14, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x23223
movl $0x1, %edi
callq 0x1f2b0