#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct stat {
  unsigned long long st_size;
};
struct rlimit {
  unsigned long long rlim_cur;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
void *MAP_FAILED;
int MAP_LOCKED;
int MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ RLIMIT_MEMLOCK;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int fstat(int, struct stat *);
scalar_t__ getpid();
int getrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ heat_the_cache(int);
int mlock(void *, unsigned long long);
void *mmap(int /*<<< orphan*/ *, unsigned long long, int /*<<< orphan*/, int,
           int, int /*<<< orphan*/);
int open(char const *const, int /*<<< orphan*/);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int main(int argc, char *argv[]) {
  unsigned long long locked_memory;
  int i, fd_null;
  fd_set phony_fdset;
  struct rlimit mlock_limit;
  if (2 > argc) {
    fprintf(
        stderr,
        "Usage:\n\n"
        "%s [filenames]\n\n"
        "Once its deed is done kill the process by sending a terminating "
        "signal.\n"
        "SIGINT (Ctrl+C) on the controlling terminal should do the trick.\n",
        argv[0]);
    return 1;
  }
  if (-1 == getrlimit(RLIMIT_MEMLOCK, &mlock_limit)) {
    fprintf(stderr, "error getrlimit(RLIMIT_MEMLOCK): %s\n", strerror(errno));
    return 1;
  }
  fprintf(stderr, "memlock rlimit: %llu\n",
          (unsigned long long)mlock_limit.rlim_cur);
  locked_memory = 0;
  for (i = 1; i < argc; ++i) {
    char const *const filename = argv[i];
    int fd;
    struct stat st;
    void *ptr;
    fprintf(stderr, "mlocking '%s'... ", filename);
  retry_open:
    fd = open(filename, O_RDONLY);
    if (-1 == fd) {
      if (EINTR == errno) {
        goto retry_open;
      } else {
        fprintf(stderr, "error open('%s'): %s\n", filename, strerror(errno));
        continue;
      }
    }
    if (-1 == fstat(fd, &st)) {
      fprintf(stderr, "error fstat(fd['%s']): %s\n", filename, strerror(errno));
      goto finish_file;
    }
    if (locked_memory + st.st_size > mlock_limit.rlim_cur) {
      fprintf(stderr,
              "error: exceeded the memlock resource limit for this process.\n"
              "Required limit to mlock '%s': %llu (counting already mlocked "
              "files)\n"
              "Locked memory resource limit set to: %llu\n"
              "Increase the locked memory resource limit and try again.\n",
              filename, (unsigned long long)locked_memory + st.st_size,
              (unsigned long long)mlock_limit.rlim_cur);
      close(fd);
      break;
    }
    ptr = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED | MAP_LOCKED, fd, 0);
    if (MAP_FAILED == ptr) {
      fprintf(stderr, "error mmap(fd['%s'], 0..%lld): %s\n", filename,
              (long long)st.st_size, strerror(errno));
      goto finish_file;
    }
    if (-1 == mlock(ptr, st.st_size)) {
      fprintf(stderr, "error mlock(ptr[fd['%s']]=%p): %s\n", filename, ptr,
              strerror(errno));
      goto finish_file;
    }
    if (locked_memory + st.st_size < locked_memory) {
      locked_memory = -1;
    } else {
      locked_memory += st.st_size;
    }
    heat_the_cache(fd);
  finish_file:
    close(fd);
    fputs("done\n", stderr);
  }
  if (!locked_memory) {
    fprintf(stderr, "nothing locked, exiting.\n");
    return 1;
  }
  fprintf(
      stderr,
      "Files locked and cache heated up. pid=%lld. Going to sleep, .zZ...\n",
      (long long)getpid());
  fd_null = open("/dev/null", O_RDONLY);
  if (-1 == fd_null) {
    fprintf(stderr, "error open('/dev/null'): %s\n", strerror(errno));
    return 1;
  }
  FD_ZERO(&phony_fdset);
  FD_SET(fd_null, &phony_fdset);
  if (-1 == select(fd_null, &phony_fdset, NULL, NULL, NULL)) {
    fprintf(stderr, "error select(...): %s\n", strerror(errno));
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
jle    1231 <main+0x51>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16cd <main+0x4ed>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   10d0 <getrlimit@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    128d <main+0xad>
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2d4b(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%rdx
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16cd <main+0x4ed>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xe26(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movq   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1588 <main+0x3a8>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x38(%rbp),%rdi
mov    0x2cdf(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x3c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x3c(%rbp),%eax
jne    1370 <main+0x190>
mov    0x2c90(%rip),%rax
mov    (%rax),%rax
mov    0x2c8e(%rip),%rcx
cmp    (%rcx),%rax
jne    1330 <main+0x150>
jmp    12ee <main+0x10e>
mov    0x2c81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2c65(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xd8b(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    157a <main+0x39a>
mov    -0x3c(%rbp),%edi
lea    -0x48(%rbp),%rsi
call   1100 <fstat@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    13cb <main+0x1eb>
mov    0x2c26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    0x2c0a(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rdx
mov    %rax,%rcx
lea    0xd46(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    155d <main+0x37d>
mov    -0x18(%rbp),%rax
add    -0x48(%rbp),%rax
cmp    -0x30(%rbp),%rax
jbe    1411 <main+0x231>
mov    0x2bd4(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%rcx
add    -0x48(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    0xd23(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x3c(%rbp),%edi
call   1070 <close@plt>
jmp    1588 <main+0x3a8>
mov    -0x48(%rbp),%rsi
mov    0x2bdc(%rip),%rax
mov    (%rax),%edx
mov    0x2bc3(%rip),%rax
mov    (%rax),%ecx
mov    0x2b92(%rip),%rax
or     (%rax),%ecx
mov    -0x3c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x50(%rbp)
mov    0x2b55(%rip),%rax
mov    (%rax),%rax
cmp    -0x50(%rbp),%rax
jne    14b0 <main+0x2d0>
mov    0x2b59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    0x2b2f(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rdx
mov    -0x80(%rbp),%rcx
mov    %rax,%r8
lea    0xd61(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    155d <main+0x37d>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1030 <mlock@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    152a <main+0x34a>
mov    0x2ae5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa4(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    0x2ab8(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    -0xa4(%rbp),%edi
mov    -0xa0(%rbp),%rdx
mov    -0x98(%rbp),%rcx
mov    %rax,%r8
lea    0xd0a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    155d <main+0x37d>
mov    -0x18(%rbp),%rax
add    -0x48(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1549 <main+0x369>
movq   $0xffffffffffffffff,-0x18(%rbp)
ff
jmp    1555 <main+0x375>
mov    -0x48(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x3c(%rbp),%edi
call   10b0 <heat_the_cache@plt>
mov    -0x3c(%rbp),%edi
call   1070 <close@plt>
mov    0x2a4c(%rip),%rax
mov    (%rax),%esi
lea    0xcd6(%rip),%rdi
call   1060 <fputs@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12b7 <main+0xd7>
cmpq   $0x0,-0x18(%rbp)
jne    15b6 <main+0x3d6>
mov    0x2a1e(%rip),%rax
mov    (%rax),%edi
lea    0xcae(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16cd <main+0x4ed>
mov    0x29fb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa8(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0xa8(%rbp),%edi
mov    %rax,%rdx
lea    0xc8f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x29ee(%rip),%rax
mov    (%rax),%esi
lea    0xcbc(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x20(%rbp)
mov    $0xffffffff,%eax
cmp    -0x20(%rbp),%eax
jne    164a <main+0x46a>
mov    0x29a8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    0x2991(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    -0xac(%rbp),%edi
mov    %rax,%rdx
lea    0xc82(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16cd <main+0x4ed>
lea    -0x24(%rbp),%rdi
call   1090 <FD_ZERO@plt>
mov    -0x20(%rbp),%edi
lea    -0x24(%rbp),%rsi
call   10f0 <FD_SET@plt>
mov    -0x20(%rbp),%edi
lea    -0x24(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10a0 <select@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    16c6 <main+0x4e6>
mov    0x292c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb0(%rbp)
mov    0x2915(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    -0xb0(%rbp),%edi
mov    %rax,%rdx
lea    0xc23(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16cd <main+0x4ed>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r15
cmp    $0x1,%edi
jg     120e <main+0x2e>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xdf7(%rip),%rsi
jmp    1576 <main+0x396>
mov    %edi,%ebp
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0x28(%rsp),%rsi
call   10d0 <getrlimit@plt>
mov    0x2d8e(%rip),%rcx
mov    (%rcx),%ebx
cmp    $0xffffffff,%eax
je     1471 <main+0x291>
mov    0x28(%rsp),%rdx
lea    0xe86(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %ebp,%eax
mov    %rax,0x30(%rsp)
mov    $0x1,%r12d
mov    0x2d7a(%rip),%rbx
mov    0x2d43(%rip),%r14
xor    %eax,%eax
mov    %rax,0x10(%rsp)
mov    0x2d45(%rip),%rbp
mov    %r15,0x8(%rsp)
jmp    12da <main+0xfa>
mov    0x2d37(%rip),%rax
mov    (%rax),%ebp
mov    0x2d26(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    %ebp,%edi
mov    0x2d1d(%rip),%rbp
lea    0xe63(%rip),%rsi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x8(%rsp),%r15
mov    %r13d,%edi
call   1070 <close@plt>
mov    0x0(%rbp),%esi
lea    0xf85(%rip),%rdi
call   1060 <fputs@plt>
add    $0x1,%r12
cmp    0x30(%rsp),%r12
je     14af <main+0x2cf>
mov    (%r15,%r12,8),%r15
mov    0x0(%rbp),%edi
lea    0xdf5(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2cb7(%rip),%rbp
nopl   0x0(%rax)
mov    (%rbx),%esi
mov    %r15,%rdi
call   10c0 <open@plt>
cmp    $0xffffffff,%eax
jne    1350 <main+0x170>
mov    0x0(%rbp),%rdi
cmp    %rdi,(%r14)
je     1300 <main+0x120>
mov    0x2c99(%rip),%rax
mov    (%rax),%ebp
call   10e0 <strerror@plt>
mov    %ebp,%edi
mov    0x2c89(%rip),%rbp
lea    0xdb9(%rip),%rsi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x8(%rsp),%r15
jmp    12cb <main+0xeb>
nopw   0x0(%rax,%rax,1)
mov    %eax,%r13d
mov    %eax,%edi
lea    0x20(%rsp),%rsi
call   1100 <fstat@plt>
cmp    $0xffffffff,%eax
je     127a <main+0x9a>
mov    0x20(%rsp),%rbp
mov    0x10(%rsp),%rax
lea    (%rax,%rbp,1),%rcx
mov    0x28(%rsp),%r8
cmp    %r8,%rcx
ja     148c <main+0x2ac>
mov    0x2c6d(%rip),%rax
mov    (%rax),%edx
mov    0x2c2c(%rip),%rax
mov    (%rax),%ecx
mov    0x2c4b(%rip),%rax
or     (%rax),%ecx
xor    %edi,%edi
mov    %rbp,%rsi
mov    %r13d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%rcx
mov    0x2be7(%rip),%rax
cmp    %rcx,(%rax)
je     13fc <main+0x21c>
mov    %rcx,0x18(%rsp)
mov    %rcx,%rdi
mov    %rbp,%rsi
call   1030 <mlock@plt>
cmp    $0xffffffff,%eax
je     1432 <main+0x252>
add    0x10(%rsp),%rbp
mov    $0xffffffffffffffff,%rax
cmovb  %rax,%rbp
mov    %r13d,%edi
call   10b0 <heat_the_cache@plt>
mov    %rbp,0x10(%rsp)
mov    0x2bc1(%rip),%rbp
jmp    12af <main+0xcf>
mov    0x2bb5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2ba0(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    0x18(%rsp),%edi
lea    0xde2(%rip),%rsi
mov    %r15,%rdx
mov    %rbp,%rcx
mov    0x2b88(%rip),%rbp
jmp    1462 <main+0x282>
mov    0x2b7f(%rip),%rax
mov    (%rax),%ebp
mov    0x2b6e(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    %ebp,%edi
mov    0x2b65(%rip),%rbp
lea    0xdce(%rip),%rsi
mov    %r15,%rdx
mov    0x18(%rsp),%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    12af <main+0xcf>
mov    0x2b38(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
lea    0xc1b(%rip),%rsi
jmp    1571 <main+0x391>
mov    0x2b25(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xc83(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r13d,%edi
call   1070 <close@plt>
mov    0x0(%rbp),%r15d
cmpq   $0x0,0x10(%rsp)
je     153f <main+0x35f>
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xd9c(%rip),%rsi
mov    %r15d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%rbx),%esi
lea    0xdca(%rip),%rdi
call   10c0 <open@plt>
cmp    $0xffffffff,%eax
je     1552 <main+0x372>
mov    %eax,%ebx
lea    0x20(%rsp),%r15
mov    %r15,%rdi
call   1090 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   10f0 <FD_SET@plt>
mov    %ebx,%edi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10a0 <select@plt>
cmp    $0xffffffff,%eax
jne    1582 <main+0x3a2>
mov    0x2a93(%rip),%rax
mov    (%rax),%ebx
mov    0x2a82(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
lea    0xd99(%rip),%rsi
jmp    1571 <main+0x391>
lea    0xd0b(%rip),%rsi
mov    %r15d,%edi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    157d <main+0x39d>
mov    0x2a5f(%rip),%rax
mov    (%rax),%ebx
mov    0x2a4e(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
lea    0xd48(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.rlimit = type { i64 }
%struct.stat = type { i64 }
@stderr = global i32 0
@.str = [162 x i8] c"Usage:\0A\0A%s [filenames]\0A\0AOnce its deed is done kill the process by sending a terminating signal.\0ASIGINT (Ctrl+C) on the controlling terminal should do the trick.\0A\00"
@RLIMIT_MEMLOCK = global i32 0
@.str.1 = [37 x i8] c"error getrlimit(RLIMIT_MEMLOCK): %s\0A\00"
@errno = global i64 0
@.str.2 = [22 x i8] c"memlock rlimit: %llu\0A\00"
@.str.3 = [18 x i8] c"mlocking '%s'... \00"
@O_RDONLY = global i32 0
@EINTR = global i64 0
@.str.4 = [22 x i8] c"error open('%s'): %s\0A\00"
@.str.5 = [27 x i8] c"error fstat(fd['%s']): %s\0A\00"
@.str.6 = [229 x i8] c"error: exceeded the memlock resource limit for this process.\0ARequired limit to mlock '%s': %llu (counting already mlocked files)\0ALocked memory resource limit set to: %llu\0AIncrease the locked memory resource limit and try again.\0A\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_LOCKED = global i32 0
@MAP_FAILED = global i8* null
@.str.7 = [35 x i8] c"error mmap(fd['%s'], 0..%lld): %s\0A\00"
@.str.8 = [35 x i8] c"error mlock(ptr[fd['%s']]=%p): %s\0A\00"
@.str.9 = [6 x i8] c"done\0A\00"
@.str.10 = [26 x i8] c"nothing locked, exiting.\0A\00"
@.str.11 = [68 x i8] c"Files locked and cache heated up. pid=%lld. Going to sleep, .zZ...\0A\00"
@.str.12 = [10 x i8] c"/dev/null\00"
@.str.13 = [29 x i8] c"error open('/dev/null'): %s\0A\00"
@.str.14 = [23 x i8] c"error select(...): %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.rlimit
%11 = alloca i8*
%12 = alloca i32
%13 = alloca %struct.stat
%14 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp sgt i32 2, %15
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 1, i32* %3
br label %186
23: ; preds = %2
%24 = load i32, i32* @RLIMIT_MEMLOCK
%25 = call i32 @getrlimit(i32 %24, %struct.rlimit* %10)
%26 = icmp eq i32 -1, %25
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = load i64, i64* @errno
%30 = call i8* @strerror(i64 %29)
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %30)
store i32 1, i32* %3
br label %186
32: ; preds = %23
%33 = load i32, i32* @stderr
%34 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %10, i32 0, i32 0
%35 = load i64, i64* %34
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %35)
store i64 0, i64* %6
store i32 1, i32* %7
br label %37
37: ; preds = %151, %32
%38 = load i32, i32* %7
%39 = load i32, i32* %4
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %154
41: ; preds = %37
%42 = load i8**, i8*** %5
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %42, i64 %44
%46 = load i8*, i8** %45
store i8* %46, i8** %11
%47 = load i32, i32* @stderr
%48 = load i8*, i8** %11
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %60, %41
%51 = load i8*, i8** %11
%52 = load i32, i32* @O_RDONLY
%53 = call i32 @open(i8* %51, i32 %52)
store i32 %53, i32* %12
%54 = load i32, i32* %12
%55 = icmp eq i32 -1, %54
br i1 %55, label %56, label %67
56: ; preds = %50
%57 = load i64, i64* @EINTR
%58 = load i64, i64* @errno
%59 = icmp eq i64 %57, %58
br i1 %59, label %60, label %61
60: ; preds = %56
br label %50
61: ; preds = %56
%62 = load i32, i32* @stderr
%63 = load i8*, i8** %11
%64 = load i64, i64* @errno
%65 = call i8* @strerror(i64 %64)
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %63, i8* %65)
br label %151
67: ; preds = %50
%68 = load i32, i32* %12
%69 = call i32 @fstat(i32 %68, %struct.stat* %13)
%70 = icmp eq i32 -1, %69
br i1 %70, label %71, label %77
71: ; preds = %67
%72 = load i32, i32* @stderr
%73 = load i8*, i8** %11
%74 = load i64, i64* @errno
%75 = call i8* @strerror(i64 %74)
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %73, i8* %75)
br label %146
77: ; preds = %67
%78 = load i64, i64* %6
%79 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%80 = load i64, i64* %79
%81 = add i64 %78, %80
%82 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %10, i32 0, i32 0
%83 = load i64, i64* %82
%84 = icmp ugt i64 %81, %83
br i1 %84, label %85, label %97
85: ; preds = %77
%86 = load i32, i32* @stderr
%87 = load i8*, i8** %11
%88 = load i64, i64* %6
%89 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%90 = load i64, i64* %89
%91 = add i64 %88, %90
%92 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %10, i32 0, i32 0
%93 = load i64, i64* %92
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([229 x i8], [229 x i8]* @.str.6, i64 0, i64 0), i8* %87, i64 %91, i64 %93)
%95 = load i32, i32* %12
%96 = call i32 @close(i32 %95)
br label %154
97: ; preds = %77
%98 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%99 = load i64, i64* %98
%100 = load i32, i32* @PROT_READ
%101 = load i32, i32* @MAP_SHARED
%102 = load i32, i32* @MAP_LOCKED
%103 = or i32 %101, %102
%104 = load i32, i32* %12
%105 = call i8* @mmap(i32* null, i64 %99, i32 %100, i32 %103, i32 %104, i32 0)
store i8* %105, i8** %14
%106 = load i8*, i8** @MAP_FAILED
%107 = load i8*, i8** %14
%108 = icmp eq i8* %106, %107
br i1 %108, label %109, label %117
109: ; preds = %97
%110 = load i32, i32* @stderr
%111 = load i8*, i8** %11
%112 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%113 = load i64, i64* %112
%114 = load i64, i64* @errno
%115 = call i8* @strerror(i64 %114)
%116 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i8* %111, i64 %113, i8* %115)
br label %146
117: ; preds = %97
%118 = load i8*, i8** %14
%119 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%120 = load i64, i64* %119
%121 = call i32 @mlock(i8* %118, i64 %120)
%122 = icmp eq i32 -1, %121
br i1 %122, label %123, label %130
123: ; preds = %117
%124 = load i32, i32* @stderr
%125 = load i8*, i8** %11
%126 = load i8*, i8** %14
%127 = load i64, i64* @errno
%128 = call i8* @strerror(i64 %127)
%129 = call i32 (i32, i8*, ...) @fprintf(i32 %124, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* %125, i8* %126, i8* %128)
br label %146
130: ; preds = %117
%131 = load i64, i64* %6
%132 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%133 = load i64, i64* %132
%134 = add i64 %131, %133
%135 = load i64, i64* %6
%136 = icmp ult i64 %134, %135
br i1 %136, label %137, label %138
137: ; preds = %130
store i64 -1, i64* %6
br label %143
138: ; preds = %130
%139 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%140 = load i64, i64* %139
%141 = load i64, i64* %6
%142 = add i64 %141, %140
store i64 %142, i64* %6
br label %143
143: ; preds = %138, %137
%144 = load i32, i32* %12
%145 = call i32 @heat_the_cache(i32 %144)
br label %146
146: ; preds = %143, %123, %109, %71
%147 = load i32, i32* %12
%148 = call i32 @close(i32 %147)
%149 = load i32, i32* @stderr
%150 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 %149)
br label %151
151: ; preds = %146, %61
%152 = load i32, i32* %7
%153 = add nsw i32 %152, 1
store i32 %153, i32* %7
br label %37
154: ; preds = %85, %37
%155 = load i64, i64* %6
%156 = icmp ne i64 %155, 0
br i1 %156, label %160, label %157
157: ; preds = %154
%158 = load i32, i32* @stderr
%159 = call i32 (i32, i8*, ...) @fprintf(i32 %158, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %3
br label %186
160: ; preds = %154
%161 = load i32, i32* @stderr
%162 = call i64 (...) @getpid()
%163 = call i32 (i32, i8*, ...) @fprintf(i32 %161, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.11, i64 0, i64 0), i64 %162)
%164 = load i32, i32* @O_RDONLY
%165 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i64 0, i64 0), i32 %164)
store i32 %165, i32* %8
%166 = load i32, i32* %8
%167 = icmp eq i32 -1, %166
br i1 %167, label %168, label %173
168: ; preds = %160
%169 = load i32, i32* @stderr
%170 = load i64, i64* @errno
%171 = call i8* @strerror(i64 %170)
%172 = call i32 (i32, i8*, ...) @fprintf(i32 %169, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.13, i64 0, i64 0), i8* %171)
store i32 1, i32* %3
br label %186
173: ; preds = %160
%174 = call i32 @FD_ZERO(i32* %9)
%175 = load i32, i32* %8
%176 = call i32 @FD_SET(i32 %175, i32* %9)
%177 = load i32, i32* %8
%178 = call i32 @select(i32 %177, i32* %9, i32* null, i32* null, i32* null)
%179 = icmp eq i32 -1, %178
br i1 %179, label %180, label %185
180: ; preds = %173
%181 = load i32, i32* @stderr
%182 = load i64, i64* @errno
%183 = call i8* @strerror(i64 %182)
%184 = call i32 (i32, i8*, ...) @fprintf(i32 %181, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i64 0, i64 0), i8* %183)
store i32 1, i32* %3
br label %186
185: ; preds = %173
store i32 0, i32* %3
br label %186
186: ; preds = %185, %180, %168, %157, %27, %17
%187 = load i32, i32* %3
ret i32 %187
}

LLVM IR (-O2):
%struct.rlimit = type { i64 }
%struct.stat = type { i64 }
@stderr = global i32 0
@.str = [162 x i8] c"Usage:\0A\0A%s [filenames]\0A\0AOnce its deed is done kill the process by sending a terminating signal.\0ASIGINT (Ctrl+C) on the controlling terminal should do the trick.\0A\00"
@RLIMIT_MEMLOCK = global i32 0
@.str.1 = [37 x i8] c"error getrlimit(RLIMIT_MEMLOCK): %s\0A\00"
@errno = global i64 0
@.str.2 = [22 x i8] c"memlock rlimit: %llu\0A\00"
@.str.3 = [18 x i8] c"mlocking '%s'... \00"
@O_RDONLY = global i32 0
@EINTR = global i64 0
@.str.4 = [22 x i8] c"error open('%s'): %s\0A\00"
@.str.5 = [27 x i8] c"error fstat(fd['%s']): %s\0A\00"
@.str.6 = [229 x i8] c"error: exceeded the memlock resource limit for this process.\0ARequired limit to mlock '%s': %llu (counting already mlocked files)\0ALocked memory resource limit set to: %llu\0AIncrease the locked memory resource limit and try again.\0A\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_LOCKED = global i32 0
@MAP_FAILED = global i8* null
@.str.7 = [35 x i8] c"error mmap(fd['%s'], 0..%lld): %s\0A\00"
@.str.8 = [35 x i8] c"error mlock(ptr[fd['%s']]=%p): %s\0A\00"
@.str.9 = [6 x i8] c"done\0A\00"
@.str.10 = [26 x i8] c"nothing locked, exiting.\0A\00"
@.str.11 = [68 x i8] c"Files locked and cache heated up. pid=%lld. Going to sleep, .zZ...\0A\00"
@.str.12 = [10 x i8] c"/dev/null\00"
@.str.13 = [29 x i8] c"error open('/dev/null'): %s\0A\00"
@.str.14 = [23 x i8] c"error select(...): %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.rlimit
%5 = alloca %struct.stat
%6 = bitcast i32* %3 to i8*
%7 = bitcast %struct.rlimit* %4 to i8*
%8 = icmp slt i32 %0, 2
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %125
13: ; preds = %2
%14 = load i32, i32* @RLIMIT_MEMLOCK
%15 = call i32 @getrlimit(i32 %14, %struct.rlimit* %4)
%16 = icmp eq i32 %15, -1
%17 = load i32, i32* @stderr
br i1 %16, label %18, label %22
18: ; preds = %13
%19 = load i64, i64* @errno
%20 = call i8* @strerror(i64 %19)
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %125
22: ; preds = %13
%23 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %4, i64 0, i32 0
%24 = load i64, i64* %23
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %24)
%26 = bitcast %struct.stat* %5 to i8*
%27 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%28 = zext i32 %0 to i64
br label %29
29: ; preds = %22, %94
%30 = phi i64 [ 1, %22 ], [ %96, %94 ]
%31 = phi i64 [ 0, %22 ], [ %95, %94 ]
%32 = getelementptr inbounds i8*, i8** %1, i64 %30
%33 = load i8*, i8** %32
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %33)
br label %36
36: ; preds = %40, %29
%37 = load i32, i32* @O_RDONLY
%38 = call i32 @open(i8* %33, i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %48
40: ; preds = %36
%41 = load i64, i64* @EINTR
%42 = load i64, i64* @errno
%43 = icmp eq i64 %41, %42
br i1 %43, label %36, label %44
44: ; preds = %40
%45 = load i32, i32* @stderr
%46 = call i8* @strerror(i64 %42)
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %33, i8* %46)
br label %94
48: ; preds = %36
%49 = call i32 @fstat(i32 %38, %struct.stat* %5)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %56
51: ; preds = %48
%52 = load i32, i32* @stderr
%53 = load i64, i64* @errno
%54 = call i8* @strerror(i64 %53)
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %33, i8* %54)
br label %85
56: ; preds = %48
%57 = load i64, i64* %27
%58 = add i64 %57, %31
%59 = load i64, i64* %23
%60 = icmp ugt i64 %58, %59
br i1 %60, label %90, label %61
61: ; preds = %56
%62 = load i32, i32* @PROT_READ
%63 = load i32, i32* @MAP_SHARED
%64 = load i32, i32* @MAP_LOCKED
%65 = or i32 %64, %63
%66 = call i8* @mmap(i32* null, i64 %57, i32 %62, i32 %65, i32 %38, i32 0)
%67 = load i8*, i8** @MAP_FAILED
%68 = icmp eq i8* %67, %66
br i1 %68, label %69, label %74
69: ; preds = %61
%70 = load i32, i32* @stderr
%71 = load i64, i64* @errno
%72 = call i8* @strerror(i64 %71)
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i8* %33, i64 %57, i8* %72)
br label %85
74: ; preds = %61
%75 = call i32 @mlock(i8* %66, i64 %57)
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %82
77: ; preds = %74
%78 = load i32, i32* @stderr
%79 = load i64, i64* @errno
%80 = call i8* @strerror(i64 %79)
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* %33, i8* %66, i8* %80)
br label %85
82: ; preds = %74
%83 = call i64 @llvm.uadd.sat.i64(i64 %31, i64 %57)
%84 = call i32 @heat_the_cache(i32 %38)
br label %85
85: ; preds = %82, %77, %69, %51
%86 = phi i64 [ %31, %51 ], [ %31, %69 ], [ %31, %77 ], [ %83, %82 ]
%87 = call i32 @close(i32 %38)
%88 = load i32, i32* @stderr
%89 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 %88)
br label %94
90: ; preds = %56
%91 = load i32, i32* @stderr
%92 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([229 x i8], [229 x i8]* @.str.6, i64 0, i64 0), i8* %33, i64 %58, i64 %59)
%93 = call i32 @close(i32 %38)
br label %98
94: ; preds = %44, %85
%95 = phi i64 [ %86, %85 ], [ %31, %44 ]
%96 = add nuw nsw i64 %30, 1
%97 = icmp eq i64 %96, %28
br i1 %97, label %98, label %29
98: ; preds = %94, %90
%99 = phi i64 [ %31, %90 ], [ %95, %94 ]
%100 = icmp eq i64 %99, 0
%101 = load i32, i32* @stderr
br i1 %100, label %102, label %104
102: ; preds = %98
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0))
br label %125
104: ; preds = %98
%105 = call i64 (...) @getpid()
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.11, i64 0, i64 0), i64 %105)
%107 = load i32, i32* @O_RDONLY
%108 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i64 0, i64 0), i32 %107)
%109 = icmp eq i32 %108, -1
br i1 %109, label %110, label %115
110: ; preds = %104
%111 = load i32, i32* @stderr
%112 = load i64, i64* @errno
%113 = call i8* @strerror(i64 %112)
%114 = call i32 (i32, i8*, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.13, i64 0, i64 0), i8* %113)
br label %125
115: ; preds = %104
%116 = call i32 @FD_ZERO(i32* %3)
%117 = call i32 @FD_SET(i32 %108, i32* %3)
%118 = call i32 @select(i32 %108, i32* %3, i32* null, i32* null, i32* null)
%119 = icmp eq i32 %118, -1
br i1 %119, label %120, label %125
120: ; preds = %115
%121 = load i32, i32* @stderr
%122 = load i64, i64* @errno
%123 = call i8* @strerror(i64 %122)
%124 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i64 0, i64 0), i8* %123)
br label %125
125: ; preds = %115, %120, %110, %102, %18, %9
%126 = phi i32 [ 1, %9 ], [ 1, %18 ], [ 1, %110 ], [ 1, %120 ], [ 1, %102 ], [ 0, %115 ]
ret i32 %126
}