// File: /workspace/github_c_makefile_star2_O2/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 0xa3464(%rip), %rbx     # 0xc76c4
pushq $0x7
popq %rdi
leaq 0x8(%rsp), %rsi
callq 0x1f7e0
cmpl $-0x1, %eax
je 0x242f0
addq $0x20, %rbx
movq 0x8(%rsp), %r14
cmpq %rbx, %r14
jae 0x24382
xorl %ebp, %ebp
pushq $0x7
popq %r15
leaq 0x8(%rsp), %r12
movq %rbx, %rax
movq %rax, %r13
cmpq %r14, %rax
jbe 0x242c8
movq %r13, 0x8(%rsp)
movq %r13, 0x10(%rsp)
movl %r15d, %edi
movq %r12, %rsi
callq 0x1f530
cmpl $-0x1, %eax
jne 0x242c8
callq 0x1f810
movl (%rax), %ebp
leaq -0x10(%r13), %rax
movq %rax, %rcx
addq $0x10, %rcx
jae 0x24292
cmpq %r14, %r13
cmovbeq %r14, %r13
cmpq %rbx, %r13
jne 0x2431c
leaq 0x66cb3(%rip), %rsi     # 0x8af8e
pushq $0x2
popq %rdi
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x22613
jmp 0x24382
callq 0x1f810
movl (%rax), %edi
callq 0x1f630
leaq 0x66a6a(%rip), %rsi     # 0x8ad6d
pushq $0x3
popq %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x22613
movl $0x3e0, 0xa33aa(%rip)   # imm = 0x3E0
jmp 0x24382
movl 0xa33a2(%rip), %edx     # 0xc76c4
addl $-0x20, %r13d
movl %r13d, 0xa3397(%rip)    # 0xc76c4
testl %r13d, %r13d
jle 0x24391
leaq 0x66b2c(%rip), %rsi     # 0x8ae65
pushq $0x3
popq %r15
movl %r15d, %edi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x22613
movl %ebp, %edi
callq 0x1f630
leaq 0x66b5a(%rip), %rsi     # 0x8aeb2
movl %r15d, %edi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x22613
movl 0xa3356(%rip), %ecx     # 0xc76c4
leaq 0x66b81(%rip), %rsi     # 0x8aef6
movl %r15d, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x22613
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x66a4a(%rip), %rsi     # 0x8ade2
pushq $0x3
popq %rdi
movq %r14, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x22613
pushq $0x1
popq %rdi
callq 0x1f2b0