#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;
int EXIT_SUCCESS;
int /*<<< orphan*/ MAP_SHARED;
int O_RDONLY;
int O_SYNC;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ _SC_PAGESIZE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ hexdump(void *, unsigned long, size_t);
void *mmap(int /*<<< orphan*/ *, size_t, int /*<<< orphan*/, int /*<<< orphan*/,
           int, unsigned long);
int /*<<< orphan*/ munmap(void *, size_t);
int open(char *, int);
int /*<<< orphan*/ printf(char *, unsigned long, size_t, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
void *strtoul(char *, char **, int /*<<< orphan*/);
size_t sysconf(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  void *p = NULL;
  char *endp = NULL;
  unsigned long offset, mapoffset;
  size_t len, pagesize;
  size_t maplen;
  int success = 0;
  pagesize = sysconf(_SC_PAGESIZE);
  if (argc >= 2) {
    offset = strtoul(argv[1], &endp, 0);
    if (endp != argv[1]) {
      len = strtoul(argv[2], &endp, 0);
      if (endp != argv[2])
        success = 1;
    }
  }
  if (!success) {
    fprintf(stderr, "Usage: %s <physical address> <length>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  printf("offset: 0x%lx len: 0x%x\n", offset, len);
  int fd = open("/dev/mem", O_RDONLY | O_SYNC);
  if (fd < 0) {
    fprintf(stderr, "Can't open /dev/mem: %m\n");
    exit(EXIT_FAILURE);
  }
  mapoffset = (offset / pagesize) * pagesize;
  maplen = ((offset - mapoffset + len + pagesize - 1) / pagesize) * pagesize;
  p = mmap(NULL, maplen, PROT_READ, MAP_SHARED, fd, mapoffset);
  if (p == NULL) {
    fprintf(stderr, "Can't mmap /dev/mem, offset 0x%lx, size 0x%x: %m\n",
            mapoffset, maplen);
    exit(EXIT_FAILURE);
  }
  if (((unsigned long)p / pagesize) * pagesize != (unsigned long)p) {
    fprintf(stderr,
            "mmap /dev/mem, offset 0x%lx, size 0x%x resulted in non-aligned "
            "address 0x%lx\n",
            mapoffset, maplen, (unsigned long)p);
    munmap(p, maplen);
    close(fd);
    exit(EXIT_FAILURE);
  }
  printf("mmap /dev/mem, offset 0x%lx, size 0x%x at address 0x%lx\n", mapoffset,
         maplen, (unsigned long)p);
  fflush(stdout);
  hexdump(p + (offset - mapoffset), offset, len);
  munmap(p, maplen);
  close(fd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   10b0 <sysconf@plt>
mov    %rax,-0x40(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     125c <main+0xac>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   10c0 <strtoul@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    0x8(%rcx),%rax
je     1257 <main+0xa7>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   10c0 <strtoul@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    0x10(%rcx),%rax
je     1252 <main+0xa2>
movl   $0x1,-0x4c(%rbp)
jmp    1257 <main+0xa7>
jmp    125c <main+0xac>
cmpl   $0x0,-0x4c(%rbp)
jne    1292 <main+0xe2>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd83(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%esi
mov    0x2d20(%rip),%rax
or     (%rax),%esi
lea    0xd7f(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
jge    12f8 <main+0x148>
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
lea    0xd66(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2cbf(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x28(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x40(%rbp)
imul   -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
sub    -0x30(%rbp),%rax
add    -0x38(%rbp),%rax
add    -0x40(%rbp),%rax
sub    $0x1,%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x40(%rbp)
imul   -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
mov    0x2cbb(%rip),%rax
mov    (%rax),%edx
mov    0x2ca2(%rip),%rax
mov    (%rax),%ecx
mov    -0x50(%rbp),%r8d
mov    -0x30(%rbp),%r9
xor    %eax,%eax
mov    %eax,%edi
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1395 <main+0x1e5>
mov    0x2c49(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
mov    -0x48(%rbp),%rcx
lea    0xce2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c22(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x40(%rbp)
imul   -0x40(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    %rcx,%rax
je     13f9 <main+0x249>
mov    0x2bfe(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xcc5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1090 <munmap@plt>
mov    -0x50(%rbp),%edi
call   1050 <close@plt>
mov    0x2bbe(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x30(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xcd6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2b8e(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
sub    -0x30(%rbp),%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1070 <hexdump@plt>
mov    -0x18(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1090 <munmap@plt>
mov    -0x50(%rbp),%edi
call   1050 <close@plt>
mov    0x2b47(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movq   $0x0,0x10(%rsp)
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   10b0 <sysconf@plt>
cmp    $0x2,%ebp
jl     13ba <main+0x20a>
mov    %rax,%r12
mov    0x8(%rbx),%rdi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   10c0 <strtoul@plt>
mov    %rax,%r13
mov    0x10(%rsp),%rax
cmp    0x8(%rbx),%rax
je     13ba <main+0x20a>
mov    0x10(%rbx),%rdi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   10c0 <strtoul@plt>
mov    %rax,%rbp
mov    0x10(%rsp),%rax
cmp    0x10(%rbx),%rax
je     13ba <main+0x20a>
mov    %r13,%rbx
lea    0xdf3(%rip),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d88(%rip),%rax
mov    0x2d89(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xde6(%rip),%rdi
call   10a0 <open@plt>
test   %eax,%eax
js     13d6 <main+0x226>
mov    %eax,%r8d
mov    %r13,%rax
or     %r12,%rax
shr    $0x20,%rax
mov    %rbx,0x18(%rsp)
je     1288 <main+0xd8>
mov    %rbx,%rax
xor    %edx,%edx
div    %r12
mov    %rdx,%r14
jmp    1292 <main+0xe2>
mov    %ebx,%eax
xor    %edx,%edx
div    %r12d
mov    %edx,%r14d
sub    %r14,%r13
mov    %rbp,%rax
add    %r12,%rax
lea    (%r14,%rax,1),%rbx
add    $0xffffffffffffffff,%rbx
mov    %rbx,%rax
or     %r12,%rax
shr    $0x20,%rax
mov    %rbp,0x20(%rsp)
je     12be <main+0x10e>
mov    %rbx,%rax
xor    %edx,%edx
div    %r12
jmp    12c5 <main+0x115>
mov    %ebx,%eax
xor    %edx,%edx
div    %r12d
sub    %rdx,%rbx
mov    0x2d29(%rip),%rax
mov    (%rax),%edx
mov    0x2d10(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %rbx,%rsi
mov    %r8d,0xc(%rsp)
mov    %r13,%r9
call   1030 <mmap@plt>
test   %rax,%rax
je     13ef <main+0x23f>
mov    %rax,%r15
mov    %r12,%rax
or     %r15,%rax
shr    $0x20,%rax
je     1377 <main+0x1c7>
mov    %r15,%rax
xor    %edx,%edx
div    %r12
test   %rdx,%rdx
jne    1384 <main+0x1d4>
lea    0xdca(%rip),%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2c79(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    %r15,%rdi
add    %r14,%rdi
mov    0x18(%rsp),%rsi
mov    0x20(%rsp),%rdx
call   1070 <hexdump@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <munmap@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
mov    0x2c3a(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15d,%eax
xor    %edx,%edx
div    %r12d
test   %rdx,%rdx
je     1311 <main+0x161>
mov    0x2c2d(%rip),%rax
mov    (%rax),%edi
lea    0xd00(%rip),%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
mov    %r15,%r8
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <munmap@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
jmp    140c <main+0x25c>
mov    0x2bf7(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xc33(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    140c <main+0x25c>
mov    0x2bdb(%rip),%rax
mov    (%rax),%edi
lea    0xc63(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    140c <main+0x25c>
mov    0x2bc2(%rip),%rax
mov    (%rax),%edi
lea    0xc63(%rip),%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2b9d(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@_SC_PAGESIZE = global i32 0
@stderr = global i32 0
@.str = [39 x i8] c"Usage: %s <physical address> <length>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [25 x i8] c"offset: 0x%lx len: 0x%x\0A\00"
@.str.2 = [9 x i8] c"/dev/mem\00"
@O_RDONLY = global i32 0
@O_SYNC = global i32 0
@.str.3 = [25 x i8] c"Can't open /dev/mem: %m\0A\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.4 = [50 x i8] c"Can't mmap /dev/mem, offset 0x%lx, size 0x%x: %m\0A\00"
@.str.5 = [78 x i8] c"mmap /dev/mem, offset 0x%lx, size 0x%x resulted in non-aligned address 0x%lx\0A\00"
@.str.6 = [57 x i8] c"mmap /dev/mem, offset 0x%lx, size 0x%x at address 0x%lx\0A\00"
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i8* null, i8** %7
store i32 0, i32* %13
%15 = load i32, i32* @_SC_PAGESIZE
%16 = call i64 @sysconf(i32 %15)
store i64 %16, i64* %11
%17 = load i32, i32* %4
%18 = icmp sge i32 %17, 2
br i1 %18, label %19, label %44
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i8* @strtoul(i8* %22, i8** %7, i32 0)
%24 = ptrtoint i8* %23 to i64
store i64 %24, i64* %8
%25 = load i8*, i8** %7
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = icmp ne i8* %25, %28
br i1 %29, label %30, label %43
30: ; preds = %19
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i8* @strtoul(i8* %33, i8** %7, i32 0)
%35 = ptrtoint i8* %34 to i64
store i64 %35, i64* %10
%36 = load i8*, i8** %7
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = icmp ne i8* %36, %39
br i1 %40, label %41, label %42
41: ; preds = %30
store i32 1, i32* %13
br label %42
42: ; preds = %41, %30
br label %43
43: ; preds = %42, %19
br label %44
44: ; preds = %43, %2
%45 = load i32, i32* %13
%46 = icmp ne i32 %45, 0
br i1 %46, label %55, label %47
47: ; preds = %44
%48 = load i32, i32* @stderr
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 0
%51 = load i8*, i8** %50
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %51)
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %44
%56 = load i64, i64* %8
%57 = load i64, i64* %10
%58 = call i32 (i8*, i64, i64, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i64 %56, i64 %57)
%59 = load i32, i32* @O_RDONLY
%60 = load i32, i32* @O_SYNC
%61 = or i32 %59, %60
%62 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %61)
store i32 %62, i32* %14
%63 = load i32, i32* %14
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %55
%66 = load i32, i32* @stderr
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%68 = load i32, i32* @EXIT_FAILURE
%69 = call i32 @exit(i32 %68)
unreachable
70: ; preds = %55
%71 = load i64, i64* %8
%72 = load i64, i64* %11
%73 = udiv i64 %71, %72
%74 = load i64, i64* %11
%75 = mul i64 %73, %74
store i64 %75, i64* %9
%76 = load i64, i64* %8
%77 = load i64, i64* %9
%78 = sub i64 %76, %77
%79 = load i64, i64* %10
%80 = add i64 %78, %79
%81 = load i64, i64* %11
%82 = add i64 %80, %81
%83 = sub i64 %82, 1
%84 = load i64, i64* %11
%85 = udiv i64 %83, %84
%86 = load i64, i64* %11
%87 = mul i64 %85, %86
store i64 %87, i64* %12
%88 = load i64, i64* %12
%89 = load i32, i32* @PROT_READ
%90 = load i32, i32* @MAP_SHARED
%91 = load i32, i32* %14
%92 = load i64, i64* %9
%93 = call i8* @mmap(i32* null, i64 %88, i32 %89, i32 %90, i32 %91, i64 %92)
store i8* %93, i8** %6
%94 = load i8*, i8** %6
%95 = icmp eq i8* %94, null
br i1 %95, label %96, label %103
96: ; preds = %70
%97 = load i32, i32* @stderr
%98 = load i64, i64* %9
%99 = load i64, i64* %12
%100 = call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i64 %98, i64 %99)
%101 = load i32, i32* @EXIT_FAILURE
%102 = call i32 @exit(i32 %101)
unreachable
103: ; preds = %70
%104 = load i8*, i8** %6
%105 = ptrtoint i8* %104 to i64
%106 = load i64, i64* %11
%107 = udiv i64 %105, %106
%108 = load i64, i64* %11
%109 = mul i64 %107, %108
%110 = load i8*, i8** %6
%111 = ptrtoint i8* %110 to i64
%112 = icmp ne i64 %109, %111
br i1 %112, label %113, label %127
113: ; preds = %103
%114 = load i32, i32* @stderr
%115 = load i64, i64* %9
%116 = load i64, i64* %12
%117 = load i8*, i8** %6
%118 = ptrtoint i8* %117 to i64
%119 = call i32 (i32, i8*, ...) @fprintf(i32 %114, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.5, i64 0, i64 0), i64 %115, i64 %116, i64 %118)
%120 = load i8*, i8** %6
%121 = load i64, i64* %12
%122 = call i32 @munmap(i8* %120, i64 %121)
%123 = load i32, i32* %14
%124 = call i32 @close(i32 %123)
%125 = load i32, i32* @EXIT_FAILURE
%126 = call i32 @exit(i32 %125)
unreachable
127: ; preds = %103
%128 = load i64, i64* %9
%129 = load i64, i64* %12
%130 = load i8*, i8** %6
%131 = ptrtoint i8* %130 to i64
%132 = call i32 (i8*, i64, i64, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.6, i64 0, i64 0), i64 %128, i64 %129, i64 %131)
%133 = load i32, i32* @stdout
%134 = call i32 @fflush(i32 %133)
%135 = load i8*, i8** %6
%136 = load i64, i64* %8
%137 = load i64, i64* %9
%138 = sub i64 %136, %137
%139 = getelementptr i8, i8* %135, i64 %138
%140 = load i64, i64* %8
%141 = load i64, i64* %10
%142 = call i32 @hexdump(i8* %139, i64 %140, i64 %141)
%143 = load i8*, i8** %6
%144 = load i64, i64* %12
%145 = call i32 @munmap(i8* %143, i64 %144)
%146 = load i32, i32* %14
%147 = call i32 @close(i32 %146)
%148 = load i32, i32* @EXIT_SUCCESS
ret i32 %148
}

LLVM IR (-O2):
@_SC_PAGESIZE = global i32 0
@stderr = global i32 0
@.str = [39 x i8] c"Usage: %s <physical address> <length>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [25 x i8] c"offset: 0x%lx len: 0x%x\0A\00"
@.str.2 = [9 x i8] c"/dev/mem\00"
@O_RDONLY = global i32 0
@O_SYNC = global i32 0
@.str.3 = [25 x i8] c"Can't open /dev/mem: %m\0A\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.4 = [50 x i8] c"Can't mmap /dev/mem, offset 0x%lx, size 0x%x: %m\0A\00"
@.str.5 = [78 x i8] c"mmap /dev/mem, offset 0x%lx, size 0x%x resulted in non-aligned address 0x%lx\0A\00"
@.str.6 = [57 x i8] c"mmap /dev/mem, offset 0x%lx, size 0x%x at address 0x%lx\0A\00"
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = load i32, i32* @_SC_PAGESIZE
%6 = tail call i64 @sysconf(i32 %5)
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %24
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i8* @strtoul(i8* %10, i8** %3, i32 0)
%12 = ptrtoint i8* %11 to i64
%13 = load i8*, i8** %3
%14 = load i8*, i8** %9
%15 = icmp eq i8* %13, %14
br i1 %15, label %24, label %16
16: ; preds = %8
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = call i8* @strtoul(i8* %18, i8** %3, i32 0)
%20 = ptrtoint i8* %19 to i64
%21 = load i8*, i8** %3
%22 = load i8*, i8** %17
%23 = icmp eq i8* %21, %22
br i1 %23, label %24, label %30
24: ; preds = %2, %8, %16
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %1
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %16
%31 = tail call i32 (i8*, i64, i64, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i64 %12, i64 %20)
%32 = load i32, i32* @O_RDONLY
%33 = load i32, i32* @O_SYNC
%34 = or i32 %33, %32
%35 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %30
%38 = load i32, i32* @stderr
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = tail call i32 @exit(i32 %40)
unreachable
42: ; preds = %30
%43 = urem i64 %12, %6
%44 = sub i64 %12, %43
%45 = add i64 %6, -1
%46 = add i64 %45, %20
%47 = add i64 %46, %43
%48 = urem i64 %47, %6
%49 = sub i64 %47, %48
%50 = load i32, i32* @PROT_READ
%51 = load i32, i32* @MAP_SHARED
%52 = tail call i8* @mmap(i32* null, i64 %49, i32 %50, i32 %51, i32 %35, i64 %44)
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %59
54: ; preds = %42
%55 = load i32, i32* @stderr
%56 = tail call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i64 %44, i64 %49)
%57 = load i32, i32* @EXIT_FAILURE
%58 = tail call i32 @exit(i32 %57)
unreachable
59: ; preds = %42
%60 = ptrtoint i8* %52 to i64
%61 = urem i64 %60, %6
%62 = icmp eq i64 %61, 0
br i1 %62, label %70, label %63
63: ; preds = %59
%64 = load i32, i32* @stderr
%65 = tail call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.5, i64 0, i64 0), i64 %44, i64 %49, i64 %60)
%66 = tail call i32 @munmap(i8* %52, i64 %49)
%67 = tail call i32 @close(i32 %35)
%68 = load i32, i32* @EXIT_FAILURE
%69 = tail call i32 @exit(i32 %68)
unreachable
70: ; preds = %59
%71 = tail call i32 (i8*, i64, i64, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.6, i64 0, i64 0), i64 %44, i64 %49, i64 %60)
%72 = load i32, i32* @stdout
%73 = tail call i32 @fflush(i32 %72)
%74 = getelementptr i8, i8* %52, i64 %43
%75 = tail call i32 @hexdump(i8* %74, i64 %12, i64 %20)
%76 = tail call i32 @munmap(i8* %52, i64 %49)
%77 = tail call i32 @close(i32 %35)
%78 = load i32, i32* @EXIT_SUCCESS
ret i32 %78
}