#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 {
  int dummy;
};

/* Variables and functions */
int MAP_ANONYMOUS;
int MAP_PRIVATE;
int MAP_SHARED;
int /*<<< orphan*/ MCL_CURRENT;
int /*<<< orphan*/ MS_SYNC;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int fstat(int, struct stat *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ mlock(void *, int);
int /*<<< orphan*/ mlockall(int /*<<< orphan*/);
void *mmap(int /*<<< orphan*/ *, int, int, int, int, int);
int /*<<< orphan*/ mprotect(void *, int, int);
void *mremap(void *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ msync(void *, int, int /*<<< orphan*/);
int /*<<< orphan*/ munlock(void *, int);
int /*<<< orphan*/ munlockall();
int /*<<< orphan*/ munmap(void *, int);
int open(char *, int, ...);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int fd, ret;
  struct stat fs;
  void *r;
  fd = open("foobar", O_WRONLY | O_CREAT | O_TRUNC, 0600);
  lseek(fd, 65536, SEEK_SET);
  write(fd, "abcdef", 6);
  close(fd);
  fd = open("foobar", O_RDONLY);
  ret = fstat(fd, &fs);
  r = mmap(NULL, 4096, PROT_READ, MAP_SHARED, fd, 0);
  mlock(r, 4096);
  msync(r, 4096, MS_SYNC);
  munlock(r, 4096);
  mlockall(MCL_CURRENT);
  munlockall();
  munmap(r, 4096);
  r = mmap(NULL, 6, PROT_READ, MAP_PRIVATE, fd, 65536);
  munmap(r, 6);
  close(fd);
  r = mmap(NULL, 12288, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1,
           0);
  mprotect(r, 4096, PROT_READ);
  munmap(r, 12288);
  r = mmap(NULL, 8192, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1,
           0);
  r = mremap(r, 8192, 4096, 0);
  munmap(r, 4096);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
mov    0x2df9(%rip),%rax
or     (%rax),%esi
mov    0x2de8(%rip),%rax
or     (%rax),%esi
lea    0xdef(%rip),%rdi
mov    $0x180,%edx
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d86(%rip),%rax
mov    (%rax),%edx
mov    $0x10000,%esi
call   1080 <lseek@plt>
mov    -0x8(%rbp),%edi
lea    0xdc7(%rip),%rsi
mov    $0x6,%edx
call   1050 <write@plt>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1100 <fstat@plt>
mov    %eax,-0xc(%rbp)
mov    0x2d66(%rip),%rax
mov    (%rax),%edx
mov    0x2d4d(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1000,%esi
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1000,%esi
call   1040 <mlock@plt>
mov    -0x18(%rbp),%rdi
mov    0x2ce9(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%esi
call   1060 <msync@plt>
mov    -0x18(%rbp),%rdi
mov    $0x1000,%esi
call   1030 <munlock@plt>
mov    0x2cc0(%rip),%rax
mov    (%rax),%edi
call   10c0 <mlockall@plt>
mov    $0x0,%al
call   10f0 <munlockall@plt>
mov    -0x18(%rbp),%rdi
mov    $0x1000,%esi
call   10b0 <munmap@plt>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edx
mov    0x2c84(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x6,%esi
mov    $0x10000,%r9d
call   1070 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x6,%esi
call   10b0 <munmap@plt>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
mov    0x2ca1(%rip),%rax
mov    (%rax),%edx
mov    0x2c48(%rip),%rax
or     (%rax),%edx
mov    0x2c37(%rip),%rax
mov    (%rax),%ecx
mov    0x2c5e(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x3000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2c5e(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%esi
call   10d0 <mprotect@plt>
mov    -0x18(%rbp),%rdi
mov    $0x3000,%esi
call   10b0 <munmap@plt>
mov    0x2c3d(%rip),%rax
mov    (%rax),%edx
mov    0x2be4(%rip),%rax
or     (%rax),%edx
mov    0x2bd3(%rip),%rax
mov    (%rax),%ecx
mov    0x2bfa(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x2000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2000,%esi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   10a0 <mremap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1000,%esi
call   10b0 <munmap@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2d8d(%rip),%rax
mov    0x2dfe(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2deb(%rip),%rax
or     (%rax),%esi
lea    0xdf2(%rip),%rbx
mov    %rbx,%rdi
mov    $0x180,%edx
xor    %eax,%eax
call   10e0 <open@plt>
mov    %eax,%ebp
mov    0x2d8a(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0x10000,%esi
call   1080 <lseek@plt>
lea    0xdcc(%rip),%rsi
mov    %ebp,%edi
mov    $0x6,%edx
call   1050 <write@plt>
mov    %ebp,%edi
call   1090 <close@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   10e0 <open@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1100 <fstat@plt>
mov    0x2d72(%rip),%r14
mov    (%r14),%edx
mov    0x2d58(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x1000,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0x1000,%esi
call   1040 <mlock@plt>
mov    0x2cfd(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    $0x1000,%esi
call   1060 <msync@plt>
mov    %rbp,%rdi
mov    $0x1000,%esi
call   1030 <munlock@plt>
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
call   10c0 <mlockall@plt>
xor    %eax,%eax
call   10f0 <munlockall@plt>
mov    %rbp,%rdi
mov    $0x1000,%esi
call   10b0 <munmap@plt>
mov    (%r14),%edx
mov    0x2c9d(%rip),%r15
mov    (%r15),%ecx
xor    %edi,%edi
mov    $0x6,%esi
mov    %ebx,%r8d
mov    $0x10000,%r9d
call   1070 <mmap@plt>
mov    %rax,%rdi
mov    $0x6,%esi
call   10b0 <munmap@plt>
mov    %ebx,%edi
call   1090 <close@plt>
mov    0x2c72(%rip),%r12
mov    (%r12),%edx
or     (%r14),%edx
mov    0x2c8c(%rip),%rbp
mov    0x0(%rbp),%ecx
or     (%r15),%ecx
xor    %edi,%edi
mov    $0x3000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    %rax,%rbx
mov    (%r14),%edx
mov    %rax,%rdi
mov    $0x1000,%esi
call   10d0 <mprotect@plt>
mov    %rbx,%rdi
mov    $0x3000,%esi
call   10b0 <munmap@plt>
mov    (%r12),%edx
or     (%r14),%edx
mov    0x0(%rbp),%ecx
or     (%r15),%ecx
xor    %edi,%edi
mov    $0x2000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    %rax,%rdi
mov    $0x2000,%esi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   10a0 <mremap@plt>
mov    %rax,%rdi
mov    $0x1000,%esi
call   10b0 <munmap@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [7 x i8] c"foobar\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [7 x i8] c"abcdef\00"
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MS_SYNC = global i32 0
@MCL_CURRENT = global i32 0
@MAP_PRIVATE = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.stat
%5 = alloca i8*
store i32 0, i32* %1
%6 = load i32, i32* @O_WRONLY
%7 = load i32, i32* @O_CREAT
%8 = or i32 %6, %7
%9 = load i32, i32* @O_TRUNC
%10 = or i32 %8, %9
%11 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %10, i32 384)
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = load i32, i32* @SEEK_SET
%14 = call i32 @lseek(i32 %12, i32 65536, i32 %13)
%15 = load i32, i32* %2
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%17 = load i32, i32* %2
%18 = call i32 @close(i32 %17)
%19 = load i32, i32* @O_RDONLY
%20 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 %20, i32* %2
%21 = load i32, i32* %2
%22 = call i32 @fstat(i32 %21, %struct.stat* %4)
store i32 %22, i32* %3
%23 = load i32, i32* @PROT_READ
%24 = load i32, i32* @MAP_SHARED
%25 = load i32, i32* %2
%26 = call i8* @mmap(i32* null, i32 4096, i32 %23, i32 %24, i32 %25, i32 0)
store i8* %26, i8** %5
%27 = load i8*, i8** %5
%28 = call i32 @mlock(i8* %27, i32 4096)
%29 = load i8*, i8** %5
%30 = load i32, i32* @MS_SYNC
%31 = call i32 @msync(i8* %29, i32 4096, i32 %30)
%32 = load i8*, i8** %5
%33 = call i32 @munlock(i8* %32, i32 4096)
%34 = load i32, i32* @MCL_CURRENT
%35 = call i32 @mlockall(i32 %34)
%36 = call i32 (...) @munlockall()
%37 = load i8*, i8** %5
%38 = call i32 @munmap(i8* %37, i32 4096)
%39 = load i32, i32* @PROT_READ
%40 = load i32, i32* @MAP_PRIVATE
%41 = load i32, i32* %2
%42 = call i8* @mmap(i32* null, i32 6, i32 %39, i32 %40, i32 %41, i32 65536)
store i8* %42, i8** %5
%43 = load i8*, i8** %5
%44 = call i32 @munmap(i8* %43, i32 6)
%45 = load i32, i32* %2
%46 = call i32 @close(i32 %45)
%47 = load i32, i32* @PROT_READ
%48 = load i32, i32* @PROT_WRITE
%49 = or i32 %47, %48
%50 = load i32, i32* @MAP_PRIVATE
%51 = load i32, i32* @MAP_ANONYMOUS
%52 = or i32 %50, %51
%53 = call i8* @mmap(i32* null, i32 12288, i32 %49, i32 %52, i32 -1, i32 0)
store i8* %53, i8** %5
%54 = load i8*, i8** %5
%55 = load i32, i32* @PROT_READ
%56 = call i32 @mprotect(i8* %54, i32 4096, i32 %55)
%57 = load i8*, i8** %5
%58 = call i32 @munmap(i8* %57, i32 12288)
%59 = load i32, i32* @PROT_READ
%60 = load i32, i32* @PROT_WRITE
%61 = or i32 %59, %60
%62 = load i32, i32* @MAP_PRIVATE
%63 = load i32, i32* @MAP_ANONYMOUS
%64 = or i32 %62, %63
%65 = call i8* @mmap(i32* null, i32 8192, i32 %61, i32 %64, i32 -1, i32 0)
store i8* %65, i8** %5
%66 = load i8*, i8** %5
%67 = call i8* @mremap(i8* %66, i32 8192, i32 4096, i32 0)
store i8* %67, i8** %5
%68 = load i8*, i8** %5
%69 = call i32 @munmap(i8* %68, i32 4096)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [7 x i8] c"foobar\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [7 x i8] c"abcdef\00"
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MS_SYNC = global i32 0
@MCL_CURRENT = global i32 0
@MAP_PRIVATE = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
define i32 @main() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = load i32, i32* @O_WRONLY
%4 = load i32, i32* @O_CREAT
%5 = or i32 %4, %3
%6 = load i32, i32* @O_TRUNC
%7 = or i32 %5, %6
%8 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %7, i32 384)
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @lseek(i32 %8, i32 65536, i32 %9)
%11 = tail call i32 @write(i32 %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%12 = tail call i32 @close(i32 %8)
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @fstat(i32 %14, %struct.stat* %1)
%16 = load i32, i32* @PROT_READ
%17 = load i32, i32* @MAP_SHARED
%18 = tail call i8* @mmap(i32* null, i32 4096, i32 %16, i32 %17, i32 %14, i32 0)
%19 = tail call i32 @mlock(i8* %18, i32 4096)
%20 = load i32, i32* @MS_SYNC
%21 = tail call i32 @msync(i8* %18, i32 4096, i32 %20)
%22 = tail call i32 @munlock(i8* %18, i32 4096)
%23 = load i32, i32* @MCL_CURRENT
%24 = tail call i32 @mlockall(i32 %23)
%25 = tail call i32 (...) @munlockall()
%26 = tail call i32 @munmap(i8* %18, i32 4096)
%27 = load i32, i32* @PROT_READ
%28 = load i32, i32* @MAP_PRIVATE
%29 = tail call i8* @mmap(i32* null, i32 6, i32 %27, i32 %28, i32 %14, i32 65536)
%30 = tail call i32 @munmap(i8* %29, i32 6)
%31 = tail call i32 @close(i32 %14)
%32 = load i32, i32* @PROT_READ
%33 = load i32, i32* @PROT_WRITE
%34 = or i32 %33, %32
%35 = load i32, i32* @MAP_PRIVATE
%36 = load i32, i32* @MAP_ANONYMOUS
%37 = or i32 %36, %35
%38 = tail call i8* @mmap(i32* null, i32 12288, i32 %34, i32 %37, i32 -1, i32 0)
%39 = load i32, i32* @PROT_READ
%40 = tail call i32 @mprotect(i8* %38, i32 4096, i32 %39)
%41 = tail call i32 @munmap(i8* %38, i32 12288)
%42 = load i32, i32* @PROT_READ
%43 = load i32, i32* @PROT_WRITE
%44 = or i32 %43, %42
%45 = load i32, i32* @MAP_PRIVATE
%46 = load i32, i32* @MAP_ANONYMOUS
%47 = or i32 %46, %45
%48 = tail call i8* @mmap(i32* null, i32 8192, i32 %44, i32 %47, i32 -1, i32 0)
%49 = tail call i8* @mremap(i8* %48, i32 8192, i32 4096, i32 0)
%50 = tail call i32 @munmap(i8* %49, i32 4096)
ret i32 0
}