#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 */
unsigned char *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_NDELAY;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ close(int);
int errno;
scalar_t__ mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
                unsigned int);
int /*<<< orphan*/ munmap(unsigned char *, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
unsigned int strtoul(char *, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  int dev_fd;
  unsigned char *map_base = NULL;
  unsigned int base = 0;
  unsigned int offs = 0;
  unsigned int val = 0;
  int rw = 0;
  int i;
  printf("--<argc=%d\n", argc);
  for (i = 0; i < argc; i++) {
    printf("--<argv[%d]=%s\n", i, argv[i]);
  }
  if (argc < 3) {
    printf("Usage: regrw <r/w> <base> <offset> [val]\n");
    return 0;
  }
  base = strtoul(argv[2], NULL, 16);
  offs = strtoul(argv[3], NULL, 16);
  if (strcmp("r", argv[1]) == 0) {
    rw = 0;
  } else {
    rw = 1;
    if (argc < 5) {
      printf("Usage: regrw <r/w> <base> <offset> [val]\n");
      return 0;
    }
    val = strtoul(argv[4], NULL, 16);
  }
  printf("%s: base=0x%08x, offs=0x%08x, val=0x%08x\n",
         rw == 0 ? "Read" : "Write", base, offs, val);
  dev_fd = open("/dev/mem", O_RDWR | O_NDELAY);
  if (dev_fd < 0) {
    printf("open(/dev/mem) failed.");
    return -1;
  }
  map_base = (unsigned char *)mmap(NULL, 0x1000, PROT_READ | PROT_WRITE,
                                   MAP_SHARED, dev_fd, base);
  if (MAP_FAILED == map_base || NULL == map_base) {
    printf("map failed! errno=%d\n", errno);
    close(dev_fd);
    return -1;
  }
  switch (rw) {
  case 0:
    val = *(volatile unsigned int *)(map_base + offs);
    printf("Read Register 0x%08x: 0x%08x\n", base + offs, val);
    break;
  case 1:
    *(volatile unsigned int *)(map_base + offs) = val;
    printf("Write Register 0x%08x with 0x%08x\n", base + offs, val);
    break;
  default:
    printf("ERROR: invalid rw %d\n", rw);
  }
  if (dev_fd)
    close(dev_fd);
  munmap(map_base, 0x1000);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f9 <main+0x89>
mov    -0x34(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11c2 <main+0x52>
cmpl   $0x3,-0x8(%rbp)
jge    121d <main+0xad>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1460 <main+0x2f0>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1090 <strtoul@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1090 <strtoul@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xde8(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1279 <main+0x109>
movl   $0x0,-0x30(%rbp)
jmp    12bd <main+0x14d>
movl   $0x1,-0x30(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    12a4 <main+0x134>
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1460 <main+0x2f0>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1090 <strtoul@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%ecx
lea    0xdb0(%rip),%rsi
lea    0xda4(%rip),%rax
cmp    $0x0,%ecx
cmove  %rax,%rsi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2ce4(%rip),%rax
mov    (%rax),%esi
mov    0x2cc3(%rip),%rax
or     (%rax),%esi
lea    0xd77(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1332 <main+0x1c2>
lea    0xd67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1460 <main+0x2f0>
mov    0x2cbf(%rip),%rax
mov    (%rax),%edx
mov    0x2c76(%rip),%rax
or     (%rax),%edx
mov    0x2c9d(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x24(%rbp),%r9d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1000,%esi
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    0x2c42(%rip),%rax
mov    (%rax),%rax
cmp    -0x20(%rbp),%rax
je     1387 <main+0x217>
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    13b2 <main+0x242>
mov    0x2c3a(%rip),%rax
mov    (%rax),%esi
lea    0xd06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1460 <main+0x2f0>
mov    -0x30(%rbp),%eax
mov    %eax,-0x38(%rbp)
test   %eax,%eax
je     13d6 <main+0x266>
jmp    13c5 <main+0x255>
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
je     13ff <main+0x28f>
jmp    1428 <main+0x2b8>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    (%rax,%rcx,1),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%esi
add    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
lea    0xcc0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1439 <main+0x2c9>
mov    -0x2c(%rbp),%edx
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    %edx,(%rax,%rcx,1)
mov    -0x24(%rbp),%esi
add    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
lea    0xcb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1439 <main+0x2c9>
mov    -0x30(%rbp),%esi
lea    0xcc2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
je     144b <main+0x2db>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%rdi
mov    $0x1000,%esi
call   1070 <munmap@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %edi,%r15d
lea    0xe68(%rip),%rdi
xor    %r14d,%r14d
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r15d,%r15d
jle    11df <main+0x5f>
mov    %r15d,%r13d
lea    0xe58(%rip),%rbp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    (%r12,%rbx,8),%rdx
mov    %rbp,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    11c0 <main+0x40>
cmp    $0x2,%r15d
jg     11fd <main+0x7d>
lea    0xee4(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%r12),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x10,%edx
call   10a0 <strtoul@plt>
mov    %eax,%ebp
mov    0x18(%r12),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10a0 <strtoul@plt>
mov    %eax,%r14d
mov    0x8(%r12),%rsi
lea    0xdea(%rip),%rdi
call   1070 <strcmp@plt>
mov    %rax,%r15
test   %rax,%rax
je     1256 <main+0xd6>
cmp    $0x4,%r13d
ja     125f <main+0xdf>
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
jmp    138a <main+0x20a>
lea    0xdeb(%rip),%rsi
jmp    1279 <main+0xf9>
mov    0x20(%r12),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10a0 <strtoul@plt>
mov    %eax,%ebx
lea    0xdd4(%rip),%rsi
lea    0xd9e(%rip),%rdi
mov    %ebp,%edx
mov    %r14d,%ecx
mov    %rbx,%r13
mov    %ebx,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d3f(%rip),%rax
mov    0x2d20(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xda8(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1318 <main+0x198>
mov    %eax,%ebx
mov    0x2d3b(%rip),%rax
mov    0x2cf4(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d19(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x1000,%esi
mov    %ebx,%r8d
mov    %ebp,%r12d
mov    %ebp,%r9d
call   1040 <mmap@plt>
test   %rax,%rax
je     1331 <main+0x1b1>
mov    %rax,%rbp
mov    0x2cbb(%rip),%rax
cmp    %rbp,(%rax)
je     1331 <main+0x1b1>
mov    %r14d,%eax
test   %r15,%r15
je     135a <main+0x1da>
mov    %r13,%rdx
mov    %edx,0x0(%rbp,%rax,1)
add    %r12d,%r14d
lea    0xd94(%rip),%rdi
mov    %r14d,%esi
jmp    136b <main+0x1eb>
lea    0xd3d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%r14d
jmp    11eb <main+0x6b>
mov    0x2c90(%rip),%rax
mov    (%rax),%esi
lea    0xd32(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    $0xffffffff,%r14d
jmp    11eb <main+0x6b>
mov    0x0(%rbp,%rax,1),%edx
add    %r12d,%r14d
lea    0xd21(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
je     137d <main+0x1fd>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %rbp,%rdi
mov    $0x1000,%esi
call   1080 <munmap@plt>
xor    %r14d,%r14d
jmp    11eb <main+0x6b>

LLVM IR (-O0):
@.str = [12 x i8] c"--<argc=%d\0A\00"
@.str.1 = [16 x i8] c"--<argv[%d]=%s\0A\00"
@.str.2 = [42 x i8] c"Usage: regrw <r/w> <base> <offset> [val]\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [42 x i8] c"%s: base=0x%08x, offs=0x%08x, val=0x%08x\0A\00"
@.str.5 = [5 x i8] c"Read\00"
@.str.6 = [6 x i8] c"Write\00"
@.str.7 = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@O_NDELAY = global i32 0
@.str.8 = [23 x i8] c"open(/dev/mem) failed.\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.9 = [22 x i8] c"map failed! errno=%d\0A\00"
@errno = global i32 0
@.str.10 = [30 x i8] c"Read Register 0x%08x: 0x%08x\0A\00"
@.str.11 = [35 x i8] c"Write Register 0x%08x with 0x%08x\0A\00"
@.str.12 = [22 x i8] c"ERROR: invalid rw %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
%13 = load i32, i32* %4
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 0, i32* %12
br label %15
15: ; preds = %27, %2
%16 = load i32, i32* %12
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = load i32, i32* %12
%21 = load i8**, i8*** %5
%22 = load i32, i32* %12
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %20, i8* %25)
br label %27
27: ; preds = %19
%28 = load i32, i32* %12
%29 = add nsw i32 %28, 1
store i32 %29, i32* %12
br label %15
30: ; preds = %15
%31 = load i32, i32* %4
%32 = icmp slt i32 %31, 3
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %135
35: ; preds = %30
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32 @strtoul(i8* %38, i32* null, i32 16)
store i32 %39, i32* %8
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 3
%42 = load i8*, i8** %41
%43 = call i32 @strtoul(i8* %42, i32* null, i32 16)
store i32 %43, i32* %9
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %35
store i32 0, i32* %11
br label %60
50: ; preds = %35
store i32 1, i32* %11
%51 = load i32, i32* %4
%52 = icmp slt i32 %51, 5
br i1 %52, label %53, label %55
53: ; preds = %50
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %135
55: ; preds = %50
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 4
%58 = load i8*, i8** %57
%59 = call i32 @strtoul(i8* %58, i32* null, i32 16)
store i32 %59, i32* %10
br label %60
60: ; preds = %55, %49
%61 = load i32, i32* %11
%62 = icmp eq i32 %61, 0
%63 = zext i1 %62 to i64
%64 = select i1 %62, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0)
%65 = load i32, i32* %8
%66 = load i32, i32* %9
%67 = load i32, i32* %10
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* %64, i32 %65, i32 %66, i32 %67)
%69 = load i32, i32* @O_RDWR
%70 = load i32, i32* @O_NDELAY
%71 = or i32 %69, %70
%72 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %71)
store i32 %72, i32* %6
%73 = load i32, i32* %6
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %60
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %3
br label %135
77: ; preds = %60
%78 = load i32, i32* @PROT_READ
%79 = load i32, i32* @PROT_WRITE
%80 = or i32 %78, %79
%81 = load i32, i32* @MAP_SHARED
%82 = load i32, i32* %6
%83 = load i32, i32* %8
%84 = call i64 @mmap(i32* null, i32 4096, i32 %80, i32 %81, i32 %82, i32 %83)
%85 = inttoptr i64 %84 to i8*
store i8* %85, i8** %7
%86 = load i8*, i8** @MAP_FAILED
%87 = load i8*, i8** %7
%88 = icmp eq i8* %86, %87
br i1 %88, label %92, label %89
89: ; preds = %77
%90 = load i8*, i8** %7
%91 = icmp eq i8* null, %90
br i1 %91, label %92, label %97
92: ; preds = %89, %77
%93 = load i32, i32* @errno
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %93)
%95 = load i32, i32* %6
%96 = call i32 @close(i32 %95)
store i32 -1, i32* %3
br label %135
97: ; preds = %89
%98 = load i32, i32* %11
switch i32 %98, label %123 [
i32 0, label %99
i32 1, label %111
]
99: ; preds = %97
%100 = load i8*, i8** %7
%101 = load i32, i32* %9
%102 = zext i32 %101 to i64
%103 = getelementptr inbounds i8, i8* %100, i64 %102
%104 = bitcast i8* %103 to i32*
%105 = load volatile i32, i32* %104
store i32 %105, i32* %10
%106 = load i32, i32* %8
%107 = load i32, i32* %9
%108 = add i32 %106, %107
%109 = load i32, i32* %10
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0), i32 %108, i32 %109)
br label %126
111: ; preds = %97
%112 = load i32, i32* %10
%113 = load i8*, i8** %7
%114 = load i32, i32* %9
%115 = zext i32 %114 to i64
%116 = getelementptr inbounds i8, i8* %113, i64 %115
%117 = bitcast i8* %116 to i32*
store volatile i32 %112, i32* %117
%118 = load i32, i32* %8
%119 = load i32, i32* %9
%120 = add i32 %118, %119
%121 = load i32, i32* %10
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0), i32 %120, i32 %121)
br label %126
123: ; preds = %97
%124 = load i32, i32* %11
%125 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i32 %124)
br label %126
126: ; preds = %123, %111, %99
%127 = load i32, i32* %6
%128 = icmp ne i32 %127, 0
br i1 %128, label %129, label %132
129: ; preds = %126
%130 = load i32, i32* %6
%131 = call i32 @close(i32 %130)
br label %132
132: ; preds = %129, %126
%133 = load i8*, i8** %7
%134 = call i32 @munmap(i8* %133, i32 4096)
store i32 0, i32* %3
br label %135
135: ; preds = %132, %92, %75, %53, %33
%136 = load i32, i32* %3
ret i32 %136
}

LLVM IR (-O2):
@.str = [12 x i8] c"--<argc=%d\0A\00"
@.str.1 = [16 x i8] c"--<argv[%d]=%s\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [42 x i8] c"%s: base=0x%08x, offs=0x%08x, val=0x%08x\0A\00"
@.str.5 = [5 x i8] c"Read\00"
@.str.6 = [6 x i8] c"Write\00"
@.str.7 = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@O_NDELAY = global i32 0
@.str.8 = [23 x i8] c"open(/dev/mem) failed.\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.9 = [22 x i8] c"map failed! errno=%d\0A\00"
@errno = global i32 0
@.str.10 = [30 x i8] c"Read Register 0x%08x: 0x%08x\0A\00"
@.str.11 = [35 x i8] c"Write Register 0x%08x with 0x%08x\0A\00"
@str.13 = [41 x i8] c"Usage: regrw <r/w> <base> <offset> [val]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %0)
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %17
5: ; preds = %2
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %13, %7 ]
%9 = getelementptr inbounds i8*, i8** %1, i64 %8
%10 = load i8*, i8** %9
%11 = trunc i64 %8 to i32
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %11, i8* %10)
%13 = add nuw nsw i64 %8, 1
%14 = icmp eq i64 %13, %6
br i1 %14, label %15, label %7
15: ; preds = %7
%16 = icmp slt i32 %0, 3
br i1 %16, label %17, label %19
17: ; preds = %2, %15
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.13, i64 0, i64 0))
br label %81
19: ; preds = %15
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32 @strtoul(i8* nocapture %21, i32* null, i32 16)
%23 = getelementptr inbounds i8*, i8** %1, i64 3
%24 = load i8*, i8** %23
%25 = tail call i32 @strtoul(i8* nocapture %24, i32* null, i32 16)
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = tail call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %38, label %30
30: ; preds = %19
%31 = icmp ult i32 %0, 5
br i1 %31, label %32, label %34
32: ; preds = %30
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.13, i64 0, i64 0))
br label %81
34: ; preds = %30
%35 = getelementptr inbounds i8*, i8** %1, i64 4
%36 = load i8*, i8** %35
%37 = tail call i32 @strtoul(i8* nocapture %36, i32* null, i32 16)
br label %38
38: ; preds = %19, %34
%39 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), %34 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), %19 ]
%40 = phi i32 [ %37, %34 ], [ 0, %19 ]
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* %39, i32 %22, i32 %25, i32 %40)
%42 = load i32, i32* @O_RDWR
%43 = load i32, i32* @O_NDELAY
%44 = or i32 %43, %42
%45 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %44)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %38
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
br label %81
49: ; preds = %38
%50 = load i32, i32* @PROT_READ
%51 = load i32, i32* @PROT_WRITE
%52 = or i32 %51, %50
%53 = load i32, i32* @MAP_SHARED
%54 = tail call i64 @mmap(i32* null, i32 4096, i32 %52, i32 %53, i32 %45, i32 %22)
%55 = inttoptr i64 %54 to i8*
%56 = load i8*, i8** @MAP_FAILED
%57 = icmp eq i8* %56, %55
%58 = icmp eq i64 %54, 0
%59 = or i1 %58, %57
br i1 %59, label %60, label %64
60: ; preds = %49
%61 = load i32, i32* @errno
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %61)
%63 = tail call i32 @close(i32 %45)
br label %81
64: ; preds = %49
%65 = zext i32 %25 to i64
%66 = getelementptr inbounds i8, i8* %55, i64 %65
%67 = bitcast i8* %66 to i32*
br i1 %29, label %68, label %72
68: ; preds = %64
%69 = load volatile i32, i32* %67
%70 = add i32 %25, %22
%71 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0), i32 %70, i32 %69)
br label %75
72: ; preds = %64
store volatile i32 %40, i32* %67
%73 = add i32 %25, %22
%74 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0), i32 %73, i32 %40)
br label %75
75: ; preds = %72, %68
%76 = icmp eq i32 %45, 0
br i1 %76, label %79, label %77
77: ; preds = %75
%78 = tail call i32 @close(i32 %45)
br label %79
79: ; preds = %77, %75
%80 = tail call i32 @munmap(i8* %55, i32 4096)
br label %81
81: ; preds = %79, %60, %47, %32, %17
%82 = phi i32 [ 0, %17 ], [ -1, %47 ], [ -1, %60 ], [ 0, %79 ], [ 0, %32 ]
ret i32 %82
}