#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 */
typedef int /*<<< orphan*/ tmpfname;
struct rlimit {
  size_t rlim_cur;
  int /*<<< orphan*/ rlim_max;
};

/* Variables and functions */
scalar_t__ EAGAIN;
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ MCL_FUTURE;
int O_CREAT;
int O_EXCL;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ RLIMIT_MEMLOCK;
int /*<<< orphan*/ RLIM_INFINITY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int ftruncate(int, size_t);
int getpid();
scalar_t__ getuid();
int mlockall(int /*<<< orphan*/);
void *mmap(int /*<<< orphan*/ *, size_t, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ set_nonroot();
int /*<<< orphan*/ seteuid(int /*<<< orphan*/);
int setrlimit(int /*<<< orphan*/, struct rlimit *);
int shm_open(char *, int, int);
int /*<<< orphan*/ shm_unlink(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
char *strerror(scalar_t__);
int main(void) {
  char tmpfname[256];
  size_t shm_size;
  void *pa;
  size_t len;
  int fd;
  size_t memlock_size;
  struct rlimit rlim = {.rlim_max = RLIM_INFINITY};
  if (mlockall(MCL_FUTURE) == -1) {
    printf("Error at mlockall(): %s\n", strerror(errno));
    return 2;
  }
  len = 1024 * 1024;
  memlock_size = len / 2;
  rlim.rlim_cur = memlock_size;
  shm_size = 1024;
  if (setrlimit(RLIMIT_MEMLOCK, &rlim) == -1) {
    printf("Error at setrlimit(): %s\n", strerror(errno));
    return 2;
  }
  snprintf(tmpfname, sizeof(tmpfname), "pts_mmap_18_1_%d", getpid());
  shm_unlink(tmpfname);
  fd = shm_open(tmpfname, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
  if (fd == -1) {
    printf("Error at shm_open(): %s\n", strerror(errno));
    return 2;
  }
  shm_unlink(tmpfname);
  if (ftruncate(fd, shm_size) == -1) {
    printf("Error at ftruncate(): %s\n", strerror(errno));
    return 2;
  }
  if (getuid() == 0) {
    if (set_nonroot() != 0) {
      printf("Cannot run this test as non-root user\n");
      return 5;
    }
  }
  pa = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  if (pa == MAP_FAILED && errno == EAGAIN) {
    printf("Got EAGAIN: %s\n", strerror(errno));
    printf("Test PASSED\n");
    seteuid(0);
    close(fd);
    munmap(pa, len);
    return 0;
  }
  if (pa == MAP_FAILED)
    perror("Error at mmap()");
  close(fd);
  munmap(pa, len);
  printf("Test FAILED: Did not get EAGAIN as expected\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x148(%rbp)
mov    0x2d64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x140(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   10d0 <mlockall@plt>
cmp    $0xffffffff,%eax
jne    126f <main+0x6f>
mov    0x2d56(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    %rax,%rsi
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1558 <main+0x358>
movq   $0x100000,-0x128(%rbp)
mov    -0x128(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rax
mov    %rax,-0x148(%rbp)
movq   $0x400,-0x118(%rbp)
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
lea    -0x148(%rbp),%rsi
call   10b0 <setrlimit@plt>
cmp    $0xffffffff,%eax
jne    12ef <main+0xef>
mov    0x2cd6(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    %rax,%rsi
lea    0xd3d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1558 <main+0x358>
lea    -0x110(%rbp),%rax
mov    %rax,-0x150(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x150(%rbp),%rdi
mov    %eax,%ecx
mov    $0x100,%esi
lea    0xd1a(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1110 <shm_unlink@plt>
lea    -0x110(%rbp),%rdi
mov    0x2c90(%rip),%rax
mov    (%rax),%esi
mov    0x2cb7(%rip),%rax
or     (%rax),%esi
mov    0x2c5e(%rip),%rax
or     (%rax),%esi
mov    0x2c3d(%rip),%rax
mov    (%rax),%edx
mov    0x2c5c(%rip),%rax
or     (%rax),%edx
call   10f0 <shm_open@plt>
mov    %eax,-0x12c(%rbp)
cmpl   $0xffffffff,-0x12c(%rbp)
jne    13a2 <main+0x1a2>
mov    0x2c23(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    %rax,%rsi
lea    0xcb5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1558 <main+0x358>
lea    -0x110(%rbp),%rdi
call   1110 <shm_unlink@plt>
mov    -0x12c(%rbp),%edi
mov    -0x118(%rbp),%rsi
call   1080 <ftruncate@plt>
cmp    $0xffffffff,%eax
jne    13f5 <main+0x1f5>
mov    0x2bd0(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    %rax,%rsi
lea    0xc7b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1558 <main+0x358>
mov    $0x0,%al
call   1040 <getuid@plt>
cmp    $0x0,%rax
jne    1436 <main+0x236>
mov    $0x0,%al
call   10a0 <set_nonroot@plt>
cmp    $0x0,%rax
je     1431 <main+0x231>
lea    0xc59(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x5,-0x4(%rbp)
jmp    1558 <main+0x358>
jmp    1436 <main+0x236>
mov    -0x128(%rbp),%rsi
mov    0x2bac(%rip),%rax
mov    (%rax),%edx
mov    0x2b4b(%rip),%rax
or     (%rax),%edx
mov    0x2b82(%rip),%rax
mov    (%rax),%ecx
mov    -0x12c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rax
mov    0x2b00(%rip),%rcx
cmp    (%rcx),%rax
jne    1502 <main+0x302>
mov    0x2b10(%rip),%rax
mov    (%rax),%rax
mov    0x2ad6(%rip),%rcx
cmp    (%rcx),%rax
jne    1502 <main+0x302>
mov    0x2af6(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    %rax,%rsi
lea    0xbe2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xbe4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   1120 <seteuid@plt>
mov    -0x12c(%rbp),%edi
call   1090 <close@plt>
mov    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rsi
call   10c0 <munmap@plt>
movl   $0x0,-0x4(%rbp)
jmp    1558 <main+0x358>
mov    -0x120(%rbp),%rax
mov    0x2a70(%rip),%rcx
cmp    (%rcx),%rax
jne    1525 <main+0x325>
lea    0xb9b(%rip),%rdi
call   10e0 <perror@plt>
mov    -0x12c(%rbp),%edi
call   1090 <close@plt>
mov    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rsi
call   10c0 <munmap@plt>
lea    0xb81(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    0x2d66(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   10e0 <mlockall@plt>
cmp    $0xffffffff,%eax
je     1361 <main+0x151>
movq   $0x80000,(%rsp)
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   10c0 <setrlimit@plt>
cmp    $0xffffffff,%eax
je     1379 <main+0x169>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xdc4(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %eax,%ecx
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1120 <shm_unlink@plt>
mov    0x2d36(%rip),%rax
mov    0x2d5f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d04(%rip),%rax
or     (%rax),%esi
mov    0x2ce3(%rip),%rax
mov    0x2d04(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbx,%rdi
call   1100 <shm_open@plt>
cmp    $0xffffffff,%eax
je     1391 <main+0x181>
mov    %eax,%ebx
lea    0x10(%rsp),%rdi
call   1120 <shm_unlink@plt>
mov    $0x400,%esi
mov    %ebx,%edi
call   1090 <ftruncate@plt>
cmp    $0xffffffff,%eax
je     13a9 <main+0x199>
xor    %eax,%eax
call   1050 <getuid@plt>
test   %rax,%rax
je     13dc <main+0x1cc>
mov    0x2cef(%rip),%rax
mov    0x2c90(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2cc5(%rip),%rax
mov    (%rax),%ecx
mov    $0x100000,%esi
xor    %edi,%edi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,%r14
mov    0x2c4f(%rip),%rax
cmp    (%rax),%r14
je     13ff <main+0x1ef>
mov    %ebx,%edi
call   10a0 <close@plt>
mov    $0x100000,%esi
mov    %r14,%rdi
call   10d0 <munmap@plt>
lea    0xd42(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
jmp    13ce <main+0x1be>
mov    0x2c38(%rip),%rax
mov    (%rax),%rdi
call   1110 <strerror@plt>
lea    0xc89(%rip),%rdi
jmp    13bf <main+0x1af>
mov    0x2c20(%rip),%rax
mov    (%rax),%rdi
call   1110 <strerror@plt>
lea    0xc8a(%rip),%rdi
jmp    13bf <main+0x1af>
mov    0x2c08(%rip),%rax
mov    (%rax),%rdi
call   1110 <strerror@plt>
lea    0xc9d(%rip),%rdi
jmp    13bf <main+0x1af>
mov    0x2bf0(%rip),%rax
mov    (%rax),%rdi
call   1110 <strerror@plt>
lea    0xc9e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%ebp
mov    %ebp,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
call   10b0 <set_nonroot@plt>
test   %rax,%rax
je     12fa <main+0xea>
lea    0xcdc(%rip),%rdi
call   1030 <puts@plt>
mov    $0x5,%ebp
jmp    13ce <main+0x1be>
mov    0x2b9a(%rip),%rax
mov    (%rax),%rdi
mov    0x2b60(%rip),%rax
cmp    (%rax),%rdi
jne    1459 <main+0x249>
call   1110 <strerror@plt>
lea    0xc56(%rip),%rdi
xor    %ebp,%ebp
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xc8f(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1130 <seteuid@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
mov    $0x100000,%esi
mov    %r14,%rdi
call   10d0 <munmap@plt>
jmp    13ce <main+0x1be>
lea    0xc27(%rip),%rdi
call   10f0 <perror@plt>
jmp    133a <main+0x12a>

LLVM IR (-O0):
%struct.rlimit = type { i64, i32 }
@RLIM_INFINITY = global i32 0
@MCL_FUTURE = global i32 0
@.str = [25 x i8] c"Error at mlockall(): %s\0A\00"
@errno = global i64 0
@RLIMIT_MEMLOCK = global i32 0
@.str.1 = [26 x i8] c"Error at setrlimit(): %s\0A\00"
@.str.2 = [17 x i8] c"pts_mmap_18_1_%d\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.3 = [25 x i8] c"Error at shm_open(): %s\0A\00"
@.str.4 = [26 x i8] c"Error at ftruncate(): %s\0A\00"
@.str.5 = [39 x i8] c"Cannot run this test as non-root user\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@EAGAIN = global i64 0
@.str.6 = [16 x i8] c"Got EAGAIN: %s\0A\00"
@.str.7 = [13 x i8] c"Test PASSED\0A\00"
@.str.8 = [16 x i8] c"Error at mmap()\00"
@.str.9 = [45 x i8] c"Test FAILED: Did not get EAGAIN as expected\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i64
%8 = alloca %struct.rlimit
store i32 0, i32* %1
%9 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %8, i32 0, i32 0
store i64 0, i64* %9
%10 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %8, i32 0, i32 1
%11 = load i32, i32* @RLIM_INFINITY
store i32 %11, i32* %10
%12 = load i32, i32* @MCL_FUTURE
%13 = call i32 @mlockall(i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %0
%16 = load i64, i64* @errno
%17 = call i8* @strerror(i64 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 2, i32* %1
br label %112
19: ; preds = %0
store i64 1048576, i64* %5
%20 = load i64, i64* %5
%21 = udiv i64 %20, 2
store i64 %21, i64* %7
%22 = load i64, i64* %7
%23 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %8, i32 0, i32 0
store i64 %22, i64* %23
store i64 1024, i64* %3
%24 = load i32, i32* @RLIMIT_MEMLOCK
%25 = call i32 @setrlimit(i32 %24, %struct.rlimit* %8)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %19
%28 = load i64, i64* @errno
%29 = call i8* @strerror(i64 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %29)
store i32 2, i32* %1
br label %112
31: ; preds = %19
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%33 = call i32 (...) @getpid()
%34 = call i32 @snprintf(i8* %32, i32 256, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%36 = call i32 @shm_unlink(i8* %35)
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%38 = load i32, i32* @O_RDWR
%39 = load i32, i32* @O_CREAT
%40 = or i32 %38, %39
%41 = load i32, i32* @O_EXCL
%42 = or i32 %40, %41
%43 = load i32, i32* @S_IRUSR
%44 = load i32, i32* @S_IWUSR
%45 = or i32 %43, %44
%46 = call i32 @shm_open(i8* %37, i32 %42, i32 %45)
store i32 %46, i32* %6
%47 = load i32, i32* %6
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %53
49: ; preds = %31
%50 = load i64, i64* @errno
%51 = call i8* @strerror(i64 %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %51)
store i32 2, i32* %1
br label %112
53: ; preds = %31
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%55 = call i32 @shm_unlink(i8* %54)
%56 = load i32, i32* %6
%57 = load i64, i64* %3
%58 = call i32 @ftruncate(i32 %56, i64 %57)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %64
60: ; preds = %53
%61 = load i64, i64* @errno
%62 = call i8* @strerror(i64 %61)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %62)
store i32 2, i32* %1
br label %112
64: ; preds = %53
%65 = call i64 (...) @getuid()
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %73
67: ; preds = %64
%68 = call i64 (...) @set_nonroot()
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %67
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
store i32 5, i32* %1
br label %112
72: ; preds = %67
br label %73
73: ; preds = %72, %64
%74 = load i64, i64* %5
%75 = load i32, i32* @PROT_READ
%76 = load i32, i32* @PROT_WRITE
%77 = or i32 %75, %76
%78 = load i32, i32* @MAP_SHARED
%79 = load i32, i32* %6
%80 = call i8* @mmap(i32* null, i64 %74, i32 %77, i32 %78, i32 %79, i32 0)
store i8* %80, i8** %4
%81 = load i8*, i8** %4
%82 = load i8*, i8** @MAP_FAILED
%83 = icmp eq i8* %81, %82
br i1 %83, label %84, label %99
84: ; preds = %73
%85 = load i64, i64* @errno
%86 = load i64, i64* @EAGAIN
%87 = icmp eq i64 %85, %86
br i1 %87, label %88, label %99
88: ; preds = %84
%89 = load i64, i64* @errno
%90 = call i8* @strerror(i64 %89)
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* %90)
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%93 = call i32 @seteuid(i32 0)
%94 = load i32, i32* %6
%95 = call i32 @close(i32 %94)
%96 = load i8*, i8** %4
%97 = load i64, i64* %5
%98 = call i32 @munmap(i8* %96, i64 %97)
store i32 0, i32* %1
br label %112
99: ; preds = %84, %73
%100 = load i8*, i8** %4
%101 = load i8*, i8** @MAP_FAILED
%102 = icmp eq i8* %100, %101
br i1 %102, label %103, label %105
103: ; preds = %99
%104 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
br label %105
105: ; preds = %103, %99
%106 = load i32, i32* %6
%107 = call i32 @close(i32 %106)
%108 = load i8*, i8** %4
%109 = load i64, i64* %5
%110 = call i32 @munmap(i8* %108, i64 %109)
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %1
br label %112
112: ; preds = %105, %88, %70, %60, %49, %27, %15
%113 = load i32, i32* %1
ret i32 %113
}

LLVM IR (-O2):
%struct.rlimit = type { i64, i32 }
@RLIM_INFINITY = global i32 0
@MCL_FUTURE = global i32 0
@.str = [25 x i8] c"Error at mlockall(): %s\0A\00"
@errno = global i64 0
@RLIMIT_MEMLOCK = global i32 0
@.str.1 = [26 x i8] c"Error at setrlimit(): %s\0A\00"
@.str.2 = [17 x i8] c"pts_mmap_18_1_%d\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.3 = [25 x i8] c"Error at shm_open(): %s\0A\00"
@.str.4 = [26 x i8] c"Error at ftruncate(): %s\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@EAGAIN = global i64 0
@.str.6 = [16 x i8] c"Got EAGAIN: %s\0A\00"
@.str.8 = [16 x i8] c"Error at mmap()\00"
@str = [44 x i8] c"Test FAILED: Did not get EAGAIN as expected\00"
@str.10 = [12 x i8] c"Test PASSED\00"
@str.11 = [38 x i8] c"Cannot run this test as non-root user\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca %struct.rlimit
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.rlimit* %2 to i8*
%5 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 1
%6 = load i32, i32* @RLIM_INFINITY
store i32 %6, i32* %5
%7 = load i32, i32* @MCL_FUTURE
%8 = tail call i32 @mlockall(i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = load i64, i64* @errno
%12 = tail call i8* @strerror(i64 %11)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %82
14: ; preds = %0
%15 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 0
store i64 524288, i64* %15
%16 = load i32, i32* @RLIMIT_MEMLOCK
%17 = call i32 @setrlimit(i32 %16, %struct.rlimit* %2)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i64, i64* @errno
%21 = call i8* @strerror(i64 %20)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %82
23: ; preds = %14
%24 = call i32 (...) @getpid()
%25 = call i32 @snprintf(i8* %3, i32 256, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = call i32 @shm_unlink(i8* %3)
%27 = load i32, i32* @O_RDWR
%28 = load i32, i32* @O_CREAT
%29 = or i32 %28, %27
%30 = load i32, i32* @O_EXCL
%31 = or i32 %29, %30
%32 = load i32, i32* @S_IRUSR
%33 = load i32, i32* @S_IWUSR
%34 = or i32 %33, %32
%35 = call i32 @shm_open(i8* %3, i32 %31, i32 %34)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %41
37: ; preds = %23
%38 = load i64, i64* @errno
%39 = call i8* @strerror(i64 %38)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %39)
br label %82
41: ; preds = %23
%42 = call i32 @shm_unlink(i8* %3)
%43 = call i32 @ftruncate(i32 %35, i64 1024)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %49
45: ; preds = %41
%46 = load i64, i64* @errno
%47 = call i8* @strerror(i64 %46)
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %47)
br label %82
49: ; preds = %41
%50 = call i64 (...) @getuid()
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %49
%53 = call i64 (...) @set_nonroot()
%54 = icmp eq i64 %53, 0
br i1 %54, label %57, label %55
55: ; preds = %52
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.11, i64 0, i64 0))
br label %82
57: ; preds = %52, %49
%58 = load i32, i32* @PROT_READ
%59 = load i32, i32* @PROT_WRITE
%60 = or i32 %59, %58
%61 = load i32, i32* @MAP_SHARED
%62 = call i8* @mmap(i32* null, i64 1048576, i32 %60, i32 %61, i32 %35, i32 0)
%63 = load i8*, i8** @MAP_FAILED
%64 = icmp eq i8* %62, %63
br i1 %64, label %65, label %78
65: ; preds = %57
%66 = load i64, i64* @errno
%67 = load i64, i64* @EAGAIN
%68 = icmp eq i64 %66, %67
br i1 %68, label %69, label %76
69: ; preds = %65
%70 = call i8* @strerror(i64 %66)
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* %70)
%72 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.10, i64 0, i64 0))
%73 = call i32 @seteuid(i32 0)
%74 = call i32 @close(i32 %35)
%75 = call i32 @munmap(i8* %62, i64 1048576)
br label %82
76: ; preds = %65
%77 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
br label %78
78: ; preds = %57, %76
%79 = call i32 @close(i32 %35)
%80 = call i32 @munmap(i8* %62, i64 1048576)
%81 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
br label %82
82: ; preds = %78, %69, %55, %45, %37, %19, %10
%83 = phi i32 [ 2, %10 ], [ 2, %19 ], [ 2, %37 ], [ 2, %45 ], [ 5, %55 ], [ 0, %69 ], [ 1, %78 ]
ret i32 %83
}