#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 */
int /*<<< orphan*/ EXIT_FAILURE;
unsigned char *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_RDONLY;
int O_SYNC;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
unsigned char *mmap(int /*<<< orphan*/, int, int /*<<< orphan*/,
                    int /*<<< orphan*/, int, int);
int munmap(unsigned char *, int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int i;
  int fd = -1;
  unsigned long pagesize;
  unsigned char *map;
  unsigned char *mem;
  fd = open("/dev/mem", O_RDONLY | O_SYNC);
  if (fd == -1) {
    perror("Error opening /dev/mem for reading");
    exit(EXIT_FAILURE);
  }
  map = mmap(0, 32 * 1024, PROT_READ, MAP_SHARED, fd, 0xFED10000);
  if (map == MAP_FAILED) {
    close(fd);
    perror("Error mmapping the file");
    exit(EXIT_FAILURE);
  }
  printf("5004-5007h: ");
  for (i = 0x5004; i < 0x5004 + 4; i++) {
    printf("%lx ", map[i]);
  }
  printf("\n");
  printf("5008-500Bh: ");
  for (i = 0x5008; i < 0x5008 + 4; i++) {
    printf("%lx ", map[i]);
  }
  printf("\n");
  if (munmap(map, 32 * 1024) == -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)
movl   $0xffffffff,-0x18(%rbp)
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
mov    0x2e3b(%rip),%rax
or     (%rax),%esi
lea    0xe5a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11d2 <main+0x62>
lea    0xe4a(%rip),%rdi
call   1080 <perror@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edx
mov    0x2e06(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%r8d
xor    %edi,%edi
mov    $0x8000,%esi
mov    $0xfed10000,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2daf(%rip),%rcx
cmp    (%rcx),%rax
jne    1234 <main+0xc4>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
lea    0xe0b(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x5004,-0x14(%rbp)
cmpl   $0x5008,-0x14(%rbp)
jge    127e <main+0x10e>
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1249 <main+0xd9>
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x5008,-0x14(%rbp)
cmpl   $0x500c,-0x14(%rbp)
jge    12d6 <main+0x166>
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12a1 <main+0x131>
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    $0x8000,%esi
call   1060 <munmap@plt>
cmp    $0xffffffff,%eax
jne    1307 <main+0x197>
lea    0xd63(%rip),%rdi
call   1080 <perror@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e45(%rip),%rax
mov    0x2e46(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe63(%rip),%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     12d6 <main+0x156>
mov    %eax,%r14d
mov    0x2e43(%rip),%rax
mov    (%rax),%edx
mov    0x2e2a(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x8000,%esi
mov    %r14d,%r8d
mov    $0xfed10000,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
mov    0x2dd9(%rip),%rax
cmp    (%rax),%rbx
je     12df <main+0x15f>
lea    0xe55(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x5004(%rbx),%esi
lea    0xe4d(%rip),%rbp
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x5005(%rbx),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x5006(%rbx),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x5007(%rbx),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe04(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x5008(%rbx),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x5009(%rbx),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x500a(%rbx),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x500b(%rbx),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
mov    $0x8000,%esi
call   1070 <munmap@plt>
cmp    $0xffffffff,%eax
je     12c8 <main+0x148>
mov    %r14d,%edi
call   1060 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd94(%rip),%rdi
call   1090 <perror@plt>
jmp    12b9 <main+0x139>
lea    0xd2c(%rip),%rdi
jmp    12ee <main+0x16e>
mov    %r14d,%edi
call   1060 <close@plt>
lea    0xd3e(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/mem\00"
@O_RDONLY = global i32 0
@O_SYNC = global i32 0
@.str.1 = [35 x i8] c"Error opening /dev/mem for reading\00"
@EXIT_FAILURE = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [24 x i8] c"Error mmapping the file\00"
@.str.3 = [13 x i8] c"5004-5007h: \00"
@.str.4 = [5 x i8] c"%lx \00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [13 x i8] c"5008-500Bh: \00"
@.str.7 = [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 i64
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %7
%11 = load i32, i32* @O_RDONLY
%12 = load i32, i32* @O_SYNC
%13 = or i32 %11, %12
%14 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i32, i32* @PROT_READ
%23 = load i32, i32* @MAP_SHARED
%24 = load i32, i32* %7
%25 = call i8* @mmap(i32 0, i32 32768, i32 %22, i32 %23, i32 %24, i32 -19857408)
store i8* %25, i8** %9
%26 = load i8*, i8** %9
%27 = load i8*, i8** @MAP_FAILED
%28 = icmp eq i8* %26, %27
br i1 %28, label %29, label %35
29: ; preds = %21
%30 = load i32, i32* %7
%31 = call i32 @close(i32 %30)
%32 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %21
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 20484, i32* %6
br label %37
37: ; preds = %48, %35
%38 = load i32, i32* %6
%39 = icmp slt i32 %38, 20488
br i1 %39, label %40, label %51
40: ; preds = %37
%41 = load i8*, i8** %9
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %40
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
store i32 %50, i32* %6
br label %37
51: ; preds = %37
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
store i32 20488, i32* %6
br label %54
54: ; preds = %65, %51
%55 = load i32, i32* %6
%56 = icmp slt i32 %55, 20492
br i1 %56, label %57, label %68
57: ; preds = %54
%58 = load i8*, i8** %9
%59 = load i32, i32* %6
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = load i8, i8* %61
%63 = zext i8 %62 to i32
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %57
%66 = load i32, i32* %6
%67 = add nsw i32 %66, 1
store i32 %67, i32* %6
br label %54
68: ; preds = %54
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%70 = load i8*, i8** %9
%71 = call i32 @munmap(i8* %70, i32 32768)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %75
73: ; preds = %68
%74 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
br label %75
75: ; preds = %73, %68
%76 = load i32, i32* %7
%77 = call i32 @close(i32 %76)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/mem\00"
@O_RDONLY = global i32 0
@O_SYNC = global i32 0
@.str.1 = [35 x i8] c"Error opening /dev/mem for reading\00"
@EXIT_FAILURE = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [24 x i8] c"Error mmapping the file\00"
@.str.3 = [13 x i8] c"5004-5007h: \00"
@.str.4 = [5 x i8] c"%lx \00"
@.str.6 = [13 x i8] c"5008-500Bh: \00"
@.str.7 = [27 x i8] c"Error un-mmapping the file\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_RDONLY
%4 = load i32, i32* @O_SYNC
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = load i32, i32* @PROT_READ
%14 = load i32, i32* @MAP_SHARED
%15 = tail call i8* @mmap(i32 0, i32 32768, i32 %13, i32 %14, i32 %6, i32 -19857408)
%16 = load i8*, i8** @MAP_FAILED
%17 = icmp eq i8* %15, %16
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = tail call i32 @close(i32 %6)
%20 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %12
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%25 = getelementptr inbounds i8, i8* %15, i64 20484
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds i8, i8* %15, i64 20485
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds i8, i8* %15, i64 20486
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = getelementptr inbounds i8, i8* %15, i64 20487
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %39)
%41 = tail call i32 @putchar(i32 10)
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%43 = getelementptr inbounds i8, i8* %15, i64 20488
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %45)
%47 = getelementptr inbounds i8, i8* %15, i64 20489
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %49)
%51 = getelementptr inbounds i8, i8* %15, i64 20490
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %53)
%55 = getelementptr inbounds i8, i8* %15, i64 20491
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %57)
%59 = tail call i32 @putchar(i32 10)
%60 = tail call i32 @munmap(i8* %15, i32 32768)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %64
62: ; preds = %23
%63 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
br label %64
64: ; preds = %62, %23
%65 = tail call i32 @close(i32 %6)
ret i32 0
}