#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*/ mode_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int lseek(int, int, int /*<<< orphan*/);
int *mmap(int /*<<< orphan*/, int, int, int /*<<< orphan*/, int,
          int /*<<< orphan*/);
int munmap(int *, int);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int i;
  int fd;
  int result;
  int *map;
  fd = open("/tmp/mmapped.bin", O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600);
  if (fd == -1) {
    perror("Error opening file for writing");
    exit(EXIT_FAILURE);
  }
  result = lseek(fd, ((1000) * sizeof(int)) - 1, SEEK_SET);
  if (result == -1) {
    close(fd);
    perror("Error calling lseek() to 'stretch' the file");
    exit(EXIT_FAILURE);
  }
  result = write(fd, "", 1);
  if (result != 1) {
    close(fd);
    perror("Error writing last byte of the file");
    exit(EXIT_FAILURE);
  }
  map = mmap(0, ((1000) * sizeof(int)), PROT_READ | PROT_WRITE, MAP_SHARED, fd,
             0);
  if (map == MAP_FAILED) {
    close(fd);
    perror("Error mmapping the file");
    exit(EXIT_FAILURE);
  }
  for (i = 1; i <= (1000); ++i) {
    map[i] = 2 * i;
  }
  if (munmap(map, ((1000) * sizeof(int))) == -1) {
    perror("Error un-mmapping the file");
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
mov    0x2e52(%rip),%rax
or     (%rax),%esi
mov    0x2e41(%rip),%rax
or     (%rax),%esi
lea    0xe48(%rip),%rdi
mov    $0x180,%edx
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11e9 <main+0x69>
lea    0xe3b(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%edi
mov    0x2dc5(%rip),%rax
mov    (%rax),%edx
mov    $0xf9f,%esi
call   1050 <lseek@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    122e <main+0xae>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
lea    0xe15(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    0xe23(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
je     1271 <main+0xf1>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
lea    0xdfe(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%edx
mov    0x2d27(%rip),%rax
or     (%rax),%edx
mov    0x2d4e(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%r8d
xor    %r9d,%r9d
mov    $0xfa0,%esi
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2cf1(%rip),%rcx
cmp    (%rcx),%rax
jne    12da <main+0x15a>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
lea    0xdb9(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cdd(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movl   $0x1,-0x14(%rbp)
cmpl   $0x3e8,-0x14(%rbp)
jg     130d <main+0x18d>
mov    -0x14(%rbp),%edx
shl    $0x1,%edx
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12e1 <main+0x161>
mov    -0x28(%rbp),%rdi
mov    $0xfa0,%esi
call   1070 <munmap@plt>
cmp    $0xffffffff,%eax
jne    1330 <main+0x1b0>
lea    0xd6d(%rip),%rdi
call   1090 <perror@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e40(%rip),%rax
mov    0x2e69(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e56(%rip),%rax
or     (%rax),%esi
lea    0xe8d(%rip),%rdi
mov    $0x180,%edx
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     12c1 <main+0x141>
mov    %eax,%ebx
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0xf9f,%esi
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
je     12ca <main+0x14a>
lea    0xeae(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    12da <main+0x15a>
mov    0x2def(%rip),%rax
mov    0x2da8(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2dcd(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0xfa0,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    0x2d7a(%rip),%rcx
cmp    (%rcx),%rax
je     12ea <main+0x16a>
movdqa 0xdc9(%rip),%xmm0
mov    $0xd,%ecx
movdqa 0xdcc(%rip),%xmm1
movdqa 0xdd4(%rip),%xmm2
nopl   0x0(%rax)
movdqa %xmm0,%xmm3
paddd  %xmm0,%xmm3
movdqu %xmm3,-0x30(%rax,%rcx,4)
paddd  %xmm1,%xmm3
movdqu %xmm3,-0x20(%rax,%rcx,4)
cmp    $0x3ed,%rcx
je     1296 <main+0x116>
movdqa %xmm0,%xmm3
paddd  %xmm1,%xmm3
paddd  %xmm3,%xmm3
movdqu %xmm3,-0x10(%rax,%rcx,4)
paddd  %xmm1,%xmm3
movdqu %xmm3,(%rax,%rcx,4)
paddd  %xmm2,%xmm0
add    $0x10,%rcx
jmp    1250 <main+0xd0>
mov    %rax,%rdi
mov    $0xfa0,%esi
call   1070 <munmap@plt>
cmp    $0xffffffff,%eax
je     12b3 <main+0x133>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe0e(%rip),%rdi
call   1090 <perror@plt>
jmp    12a8 <main+0x128>
lea    0xd79(%rip),%rdi
jmp    12f8 <main+0x178>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xd88(%rip),%rdi
jmp    12f8 <main+0x178>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xda4(%rip),%rdi
jmp    12f8 <main+0x178>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xdb8(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"/tmp/mmapped.bin\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [31 x i8] c"Error opening file for writing\00"
@EXIT_FAILURE = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [44 x i8] c"Error calling lseek() to 'stretch' the file\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [36 x i8] c"Error writing last byte of the file\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i32* null
@.str.5 = [24 x i8] c"Error mmapping the file\00"
@.str.6 = [27 x i8] c"Error un-mmapping the file\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @O_RDWR
%11 = load i32, i32* @O_CREAT
%12 = or i32 %10, %11
%13 = load i32, i32* @O_TRUNC
%14 = or i32 %12, %13
%15 = call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %14, i32 384)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = load i32, i32* %7
%24 = load i32, i32* @SEEK_SET
%25 = call i32 @lseek(i32 %23, i32 3999, i32 %24)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %34
28: ; preds = %22
%29 = load i32, i32* %7
%30 = call i32 @close(i32 %29)
%31 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %22
%35 = load i32, i32* %7
%36 = call i32 @write(i32 %35, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 1)
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = icmp ne i32 %37, 1
br i1 %38, label %39, label %45
39: ; preds = %34
%40 = load i32, i32* %7
%41 = call i32 @close(i32 %40)
%42 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %34
%46 = load i32, i32* @PROT_READ
%47 = load i32, i32* @PROT_WRITE
%48 = or i32 %46, %47
%49 = load i32, i32* @MAP_SHARED
%50 = load i32, i32* %7
%51 = call i32* @mmap(i32 0, i32 4000, i32 %48, i32 %49, i32 %50, i32 0)
store i32* %51, i32** %9
%52 = load i32*, i32** %9
%53 = load i32*, i32** @MAP_FAILED
%54 = icmp eq i32* %52, %53
br i1 %54, label %55, label %61
55: ; preds = %45
%56 = load i32, i32* %7
%57 = call i32 @close(i32 %56)
%58 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %45
store i32 1, i32* %6
br label %62
62: ; preds = %72, %61
%63 = load i32, i32* %6
%64 = icmp sle i32 %63, 1000
br i1 %64, label %65, label %75
65: ; preds = %62
%66 = load i32, i32* %6
%67 = mul nsw i32 2, %66
%68 = load i32*, i32** %9
%69 = load i32, i32* %6
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i32, i32* %68, i64 %70
store i32 %67, i32* %71
br label %72
72: ; preds = %65
%73 = load i32, i32* %6
%74 = add nsw i32 %73, 1
store i32 %74, i32* %6
br label %62
75: ; preds = %62
%76 = load i32*, i32** %9
%77 = call i32 @munmap(i32* %76, i32 4000)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %81
79: ; preds = %75
%80 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
br label %81
81: ; preds = %79, %75
%82 = load i32, i32* %7
%83 = call i32 @close(i32 %82)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"/tmp/mmapped.bin\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [31 x i8] c"Error opening file for writing\00"
@EXIT_FAILURE = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [44 x i8] c"Error calling lseek() to 'stretch' the file\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [36 x i8] c"Error writing last byte of the file\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i32* null
@.str.5 = [24 x i8] c"Error mmapping the file\00"
@.str.6 = [27 x i8] c"Error un-mmapping the file\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_RDWR
%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 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %7, i32 384)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i32, i32* @SEEK_SET
%16 = tail call i32 @lseek(i32 %8, i32 3999, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = tail call i32 @close(i32 %8)
%20 = tail call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %14
%24 = tail call i32 @write(i32 %8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 1)
%25 = icmp eq i32 %24, 1
br i1 %25, label %31, label %26
26: ; preds = %23
%27 = tail call i32 @close(i32 %8)
%28 = tail call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %23
%32 = load i32, i32* @PROT_READ
%33 = load i32, i32* @PROT_WRITE
%34 = or i32 %33, %32
%35 = load i32, i32* @MAP_SHARED
%36 = tail call i32* @mmap(i32 0, i32 4000, i32 %34, i32 %35, i32 %8, i32 0)
%37 = load i32*, i32** @MAP_FAILED
%38 = icmp eq i32* %36, %37
br i1 %38, label %63, label %39
39: ; preds = %31, %52
%40 = phi i64 [ %61, %52 ], [ 0, %31 ]
%41 = phi <4 x i32> [ %62, %52 ], [ <i32 1, i32 2, i32 3, i32 4>, %31 ]
%42 = or i64 %40, 1
%43 = getelementptr inbounds i32, i32* %36, i64 %42
%44 = shl <4 x i32> %41, <i32 1, i32 1, i32 1, i32 1>
%45 = shl <4 x i32> %41, <i32 1, i32 1, i32 1, i32 1>
%46 = add <4 x i32> %45, <i32 8, i32 8, i32 8, i32 8>
%47 = bitcast i32* %43 to <4 x i32>*
store <4 x i32> %44, <4 x i32>* %47
%48 = getelementptr inbounds i32, i32* %43, i64 4
%49 = bitcast i32* %48 to <4 x i32>*
store <4 x i32> %46, <4 x i32>* %49
%50 = add <4 x i32> %41, <i32 8, i32 8, i32 8, i32 8>
%51 = icmp eq i64 %40, 992
br i1 %51, label %68, label %52
52: ; preds = %39
%53 = or i64 %40, 9
%54 = getelementptr inbounds i32, i32* %36, i64 %53
%55 = shl <4 x i32> %50, <i32 1, i32 1, i32 1, i32 1>
%56 = shl <4 x i32> %50, <i32 1, i32 1, i32 1, i32 1>
%57 = add <4 x i32> %56, <i32 8, i32 8, i32 8, i32 8>
%58 = bitcast i32* %54 to <4 x i32>*
store <4 x i32> %55, <4 x i32>* %58
%59 = getelementptr inbounds i32, i32* %54, i64 4
%60 = bitcast i32* %59 to <4 x i32>*
store <4 x i32> %57, <4 x i32>* %60
%61 = add nuw nsw i64 %40, 16
%62 = add <4 x i32> %41, <i32 16, i32 16, i32 16, i32 16>
br label %39
63: ; preds = %31
%64 = tail call i32 @close(i32 %8)
%65 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%66 = load i32, i32* @EXIT_FAILURE
%67 = tail call i32 @exit(i32 %66)
unreachable
68: ; preds = %39
%69 = tail call i32 @munmap(i32* %36, i32 4000)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
br label %73
73: ; preds = %71, %68
%74 = tail call i32 @close(i32 %8)
ret i32 0
}