// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movl 0xec746(%rip), %eax     # 0x114014
addl $0x20, %eax
cltq
movq %rax, -0x8(%rbp)
movl $0x7, %edi
leaq -0x18(%rbp), %rsi
callq 0x1f7f0
cmpl $-0x1, %eax
jne 0x2791b
callq 0x1f820
movl (%rax), %edi
callq 0x1f630
movq %rax, %rdx
movl $0x3, %edi
leaq 0xb74d0(%rip), %rsi     # 0xdedd5
movb $0x0, %al
callq 0x24fb0
movl $0x3e0, 0xec6fe(%rip)   # imm = 0x3E0
jmp 0x27a87
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x8(%rbp), %rax
jae 0x27a85
movl $0x0, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
jbe 0x279a0
movl $0x10, -0x30(%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 0x1f510
cmpl $-0x1, %eax
je 0x27976
jmp 0x279a0
callq 0x1f820
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
cmpq %rcx, %rax
jae 0x2798f
jmp 0x279a0
movslq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x28(%rbp)
jmp 0x27940
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x279b2
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x8(%rbp), %rax
je 0x27a68
movl 0xec64e(%rip), %eax     # 0x114014
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
subq $0x20, %rax
movl %eax, 0xec63d(%rip)     # 0x114014
cmpl $0x1, 0xec636(%rip)     # 0x114014
jge 0x27a05
movq -0x20(%rbp), %rdx
movq -0x8(%rbp), %rcx
movl $0x3, %edi
leaq 0xb7456(%rip), %rsi     # 0xdee4a
movb $0x0, %al
callq 0x24fb0
movl $0x1, %edi
callq 0x1f2c0
movl -0x34(%rbp), %edx
movq -0x8(%rbp), %rcx
movl $0x3, %edi
leaq 0xb74b5(%rip), %rsi     # 0xdeecd
movb $0x0, %al
callq 0x24fb0
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x2c(%rbp), %edi
callq 0x1f630
movq -0x40(%rbp), %rdx
movq %rax, %rcx
movl $0x3, %edi
leaq 0xb74d8(%rip), %rsi     # 0xdef1a
movb $0x0, %al
callq 0x24fb0
movq -0x20(%rbp), %rdx
movl 0xec5c1(%rip), %ecx     # 0x114014
movl $0x3, %edi
leaq 0xb74ff(%rip), %rsi     # 0xdef5e
movb $0x0, %al
callq 0x24fb0
jmp 0x27a83
movq -0x8(%rbp), %rdx
movq -0x20(%rbp), %rcx
movl $0x2, %edi
leaq 0xb757a(%rip), %rsi     # 0xdeff6
movb $0x0, %al
callq 0x24fb0
jmp 0x27a85
jmp 0x27a87
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)