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

/* Variables and functions */
char *MAP_FAILED;
int MAP_FILE;
int MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ close(int);
char *mmap(int /*<<< orphan*/, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int main(void) {
  int i;
  int fd;
  char *mem;
  if ((fd = open("temp", O_RDWR)) < 0) {
    perror("open error");
    return 1;
  }
  mem = mmap(0, 10, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0);
  if (mem == MAP_FAILED) {
    perror("mmap error2:");
    return 1;
  }
  for (i = 0; i < 5; i++) {
    char temp;
    temp = mem[i];
    mem[i] = mem[9 - i];
    mem[9 - i] = temp;
  }
  munmap(mem, 10);
  close(fd);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1198 <main+0x48>
lea    0xe7e(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    127c <main+0x12c>
mov    0x2e59(%rip),%rax
mov    (%rax),%edx
mov    0x2e18(%rip),%rax
or     (%rax),%edx
mov    0x2e1f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e2e(%rip),%rax
or     (%rax),%ecx
mov    -0xc(%rbp),%r8d
xor    %r9d,%r9d
mov    $0xa,%esi
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2dd9(%rip),%rcx
cmp    (%rcx),%rax
jne    1200 <main+0xb0>
lea    0xe21(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    127c <main+0x12c>
movl   $0x0,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    125f <main+0x10f>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x9,%ecx
sub    -0x8(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x19(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    $0x9,%ecx
sub    -0x8(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1207 <main+0xb7>
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1050 <munmap@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1200 <main+0xb0>
mov    %eax,%ebx
mov    0x2e81(%rip),%rax
mov    0x2e42(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e47(%rip),%rax
mov    0x2e58(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0xa,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2e0b(%rip),%rcx
cmp    (%rcx),%rax
je     1209 <main+0xb9>
movzwl (%rax),%ecx
rol    $0x8,%cx
movzwl 0x8(%rax),%edx
rol    $0x8,%dx
movzwl 0x2(%rax),%esi
mov    %dx,(%rax)
rol    $0x8,%si
mov    %cx,0x8(%rax)
movzwl 0x6(%rax),%ecx
rol    $0x8,%cx
mov    %cx,0x2(%rax)
mov    %si,0x6(%rax)
rolw   $0x8,0x4(%rax)
mov    %rax,%rdi
mov    $0xa,%esi
call   1050 <munmap@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    $0x1,%eax
pop    %rbx
ret
lea    0xdfe(%rip),%rdi
jmp    1210 <main+0xc0>
lea    0xe00(%rip),%rdi
call   1070 <perror@plt>
jmp    11f9 <main+0xa9>

LLVM IR (-O0):
@.str = [5 x i8] c"temp\00"
@O_RDWR = global i32 0
@.str.1 = [11 x i8] c"open error\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_FILE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [13 x i8] c"mmap error2:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8
store i32 0, i32* %1
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %59
11: ; preds = %0
%12 = load i32, i32* @PROT_READ
%13 = load i32, i32* @PROT_WRITE
%14 = or i32 %12, %13
%15 = load i32, i32* @MAP_FILE
%16 = load i32, i32* @MAP_SHARED
%17 = or i32 %15, %16
%18 = load i32, i32* %3
%19 = call i8* @mmap(i32 0, i32 10, i32 %14, i32 %17, i32 %18, i32 0)
store i8* %19, i8** %4
%20 = load i8*, i8** %4
%21 = load i8*, i8** @MAP_FAILED
%22 = icmp eq i8* %20, %21
br i1 %22, label %23, label %25
23: ; preds = %11
%24 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %59
25: ; preds = %11
store i32 0, i32* %2
br label %26
26: ; preds = %51, %25
%27 = load i32, i32* %2
%28 = icmp slt i32 %27, 5
br i1 %28, label %29, label %54
29: ; preds = %26
%30 = load i8*, i8** %4
%31 = load i32, i32* %2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
store i8 %34, i8* %5
%35 = load i8*, i8** %4
%36 = load i32, i32* %2
%37 = sub nsw i32 9, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
%40 = load i8, i8* %39
%41 = load i8*, i8** %4
%42 = load i32, i32* %2
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 %40, i8* %44
%45 = load i8, i8* %5
%46 = load i8*, i8** %4
%47 = load i32, i32* %2
%48 = sub nsw i32 9, %47
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %46, i64 %49
store i8 %45, i8* %50
br label %51
51: ; preds = %29
%52 = load i32, i32* %2
%53 = add nsw i32 %52, 1
store i32 %53, i32* %2
br label %26
54: ; preds = %26
%55 = load i8*, i8** %4
%56 = call i32 @munmap(i8* %55, i32 10)
%57 = load i32, i32* %3
%58 = call i32 @close(i32 %57)
store i32 1, i32* %1
br label %59
59: ; preds = %54, %23, %9
%60 = load i32, i32* %1
ret i32 %60
}

LLVM IR (-O2):
@.str = [5 x i8] c"temp\00"
@O_RDWR = global i32 0
@.str.1 = [11 x i8] c"open error\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_FILE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [13 x i8] c"mmap error2:\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %40
6: ; preds = %0
%7 = load i32, i32* @PROT_READ
%8 = load i32, i32* @PROT_WRITE
%9 = or i32 %8, %7
%10 = load i32, i32* @MAP_FILE
%11 = load i32, i32* @MAP_SHARED
%12 = or i32 %11, %10
%13 = tail call i8* @mmap(i32 0, i32 10, i32 %9, i32 %12, i32 %2, i32 0)
%14 = load i8*, i8** @MAP_FAILED
%15 = icmp eq i8* %13, %14
br i1 %15, label %38, label %16
16: ; preds = %6
%17 = load i8, i8* %13
%18 = getelementptr inbounds i8, i8* %13, i64 9
%19 = load i8, i8* %18
store i8 %19, i8* %13
store i8 %17, i8* %18
%20 = getelementptr inbounds i8, i8* %13, i64 1
%21 = load i8, i8* %20
%22 = getelementptr inbounds i8, i8* %13, i64 8
%23 = load i8, i8* %22
store i8 %23, i8* %20
store i8 %21, i8* %22
%24 = getelementptr inbounds i8, i8* %13, i64 2
%25 = load i8, i8* %24
%26 = getelementptr inbounds i8, i8* %13, i64 7
%27 = load i8, i8* %26
store i8 %27, i8* %24
store i8 %25, i8* %26
%28 = getelementptr inbounds i8, i8* %13, i64 3
%29 = load i8, i8* %28
%30 = getelementptr inbounds i8, i8* %13, i64 6
%31 = load i8, i8* %30
store i8 %31, i8* %28
store i8 %29, i8* %30
%32 = getelementptr inbounds i8, i8* %13, i64 4
%33 = load i8, i8* %32
%34 = getelementptr inbounds i8, i8* %13, i64 5
%35 = load i8, i8* %34
store i8 %35, i8* %32
store i8 %33, i8* %34
%36 = tail call i32 @munmap(i8* %13, i32 10)
%37 = tail call i32 @close(i32 %2)
br label %40
38: ; preds = %6
%39 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %16, %38, %4
ret i32 1
}