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

/* Variables and functions */
char *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ getpagesize();
char *mmap(int /*<<< orphan*/ *, int /*<<< orphan*/, int, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read_bytes(char *, long, unsigned int);
scalar_t__ sscanf(char *, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncmp(char *, char *, int);
int /*<<< orphan*/ usage(char *);
int /*<<< orphan*/ write_bytes(char *, unsigned long, unsigned char);
int main(int argc, char *argv[]) {
  char *mem, *command;
  int fd;
  long addr;
  unsigned int size;
  if (argc < 4) {
    usage(argv[0]);
    exit(1);
  }
  if (sscanf(argv[1], "%ms", &command) <= 0) {
    usage(argv[0]);
    {
      fprintf(stderr, "%s\n", (("\nFailed to read command (read/write)")));
      exit(1);
    };
  }
  if (sscanf(argv[2], "%10lx", &addr) <= 0) {
    usage(argv[0]);
    {
      fprintf(stderr, "%s\n",
              (("\nFailed to read address (must be hexadecimal, prefixed with "
                "0x)")));
      exit(1);
    };
  }
  fd = open("/dev/mem", O_RDWR);
  if (fd <= 0) {
    {
      fprintf(stderr, "%s\n", (("Failed to open /dev/mem")));
      exit(1);
    };
  }
  mem = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_SHARED, fd,
             (off_t)addr);
  assert(mem != MAP_FAILED);
  if (!strncmp(command, "read", 4)) {
    if (sscanf(argv[3], "%10u", &size) <= 0) {
      usage(argv[0]);
      {
        fprintf(stderr, "%s\n",
                (("\nFailed to read count (must be decimal integer value)")));
        exit(1);
      };
    }
    read_bytes(mem, addr, size);
  } else if (!strncmp(command, "write", 5)) {
    unsigned char value;
    unsigned long offset;
    if (argc != 5) {
      usage(argv[0]);
      {
        fprintf(stderr, "%s\n", (("\nNot enough arguments")));
        exit(1);
      };
    }
    if (sscanf(argv[3], "%10lx", &offset) <= 0) {
      usage(argv[0]);
      {
        fprintf(stderr, "%s\n",
                (("\nFailed to read offset (must be hexadecimal, prefixed with "
                  "0x)")));
        exit(1);
      };
    }
    if (sscanf(argv[4] + 2, "%02hhx", &value) <= 0) {
      usage(argv[0]);
      {
        fprintf(stderr, "%s\n",
                (("\nFailed to read value (must be hexadecimal, prefixed with "
                  "0x)")));
        exit(1);
      };
    }
    write_bytes(mem, offset, value);
  } else {
    usage(argv[0]);
    exit(1);
  }
  munmap(mem, getpagesize());
  close(fd);
  return 0;
}


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)
cmpl   $0x4,-0x8(%rbp)
jge    1206 <main+0x36>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <usage@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdeb(%rip),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   10a0 <sscanf@plt>
cmp    $0x0,%rax
jg     125c <main+0x8c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <usage@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xdbe(%rip),%rsi
lea    0xdbb(%rip),%rdx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdc2(%rip),%rsi
lea    -0x30(%rbp),%rdx
mov    $0x0,%al
call   10a0 <sscanf@plt>
cmp    $0x0,%rax
jg     12b2 <main+0xe2>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <usage@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
lea    0xd68(%rip),%rsi
lea    0xd90(%rip),%rdx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    0x2d1f(%rip),%rax
mov    (%rax),%esi
lea    0xdc0(%rip),%rdi
call   10d0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jg     12fa <main+0x12a>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
lea    0xd20(%rip),%rsi
lea    0xd88(%rip),%rdx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    $0x0,%al
call   10e0 <getpagesize@plt>
mov    %eax,%esi
mov    0x2cee(%rip),%rax
mov    (%rax),%edx
mov    0x2cad(%rip),%rax
or     (%rax),%edx
mov    0x2ccc(%rip),%rax
mov    (%rax),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x30(%rbp),%rax
mov    %eax,%r9d
xor    %eax,%eax
mov    %eax,%edi
call   1050 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2c77(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x20(%rbp),%rdi
lea    0xd2f(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    13da <main+0x20a>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xd12(%rip),%rsi
lea    -0x34(%rbp),%rdx
mov    $0x0,%al
call   10a0 <sscanf@plt>
cmp    $0x0,%rax
jg     13c5 <main+0x1f5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <usage@plt>
mov    0x2c22(%rip),%rax
mov    (%rax),%edi
lea    0xc55(%rip),%rsi
lea    0xcdf(%rip),%rdx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1040 <read_bytes@plt>
jmp    1515 <main+0x345>
mov    -0x20(%rbp),%rdi
lea    0xce6(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    14fa <main+0x32a>
cmpl   $0x5,-0x8(%rbp)
je     1434 <main+0x264>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <usage@plt>
mov    0x2bb3(%rip),%rax
mov    (%rax),%edi
lea    0xbe6(%rip),%rsi
lea    0xcac(%rip),%rdx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xbea(%rip),%rsi
lea    -0x40(%rbp),%rdx
mov    $0x0,%al
call   10a0 <sscanf@plt>
cmp    $0x0,%rax
jg     148a <main+0x2ba>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <usage@plt>
mov    0x2b5d(%rip),%rax
mov    (%rax),%edi
lea    0xb90(%rip),%rsi
lea    0xc6c(%rip),%rdx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
add    $0x2,%rdi
lea    0xc89(%rip),%rsi
lea    -0x35(%rbp),%rdx
mov    $0x0,%al
call   10a0 <sscanf@plt>
cmp    $0x0,%rax
jg     14e4 <main+0x314>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <usage@plt>
mov    0x2b03(%rip),%rax
mov    (%rax),%edi
lea    0xb36(%rip),%rsi
lea    0xc58(%rip),%rdx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%rsi
movzbl -0x35(%rbp),%edx
call   1090 <write_bytes@plt>
jmp    1510 <main+0x340>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <usage@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
jmp    1515 <main+0x345>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   10e0 <getpagesize@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
call   10b0 <munmap@plt>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jle    1389 <main+0x1b9>
mov    %edi,%r15d
mov    0x8(%rbx),%rdi
lea    0xe0c(%rip),%rsi
lea    0x20(%rsp),%rdx
xor    %eax,%eax
call   10a0 <sscanf@plt>
test   %rax,%rax
jle    139b <main+0x1cb>
mov    0x10(%rbx),%rdi
lea    0xe19(%rip),%rsi
lea    0x18(%rsp),%rdx
xor    %eax,%eax
call   10a0 <sscanf@plt>
test   %rax,%rax
jle    13bf <main+0x1ef>
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
lea    0xe49(%rip),%rdi
call   10d0 <open@plt>
test   %eax,%eax
jle    13e3 <main+0x213>
mov    %eax,%r14d
xor    %eax,%eax
call   10e0 <getpagesize@plt>
mov    0x2da1(%rip),%rcx
mov    0x2d62(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2d7f(%rip),%rcx
mov    (%rcx),%ecx
mov    0x18(%rsp),%r9d
xor    %edi,%edi
mov    %eax,%esi
mov    %r14d,%r8d
call   1050 <mmap@plt>
mov    %rax,%rbp
mov    0x2d32(%rip),%rax
xor    %edi,%edi
cmp    (%rax),%rbp
setne  %dil
call   1070 <assert@plt>
mov    0x20(%rsp),%rdi
lea    0xdeb(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1332 <main+0x162>
mov    0x20(%rsp),%rdi
lea    0xe0d(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1389 <main+0x1b9>
cmp    $0x5,%r15d
jne    13ff <main+0x22f>
mov    0x18(%rbx),%rdi
lea    0xd48(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   10a0 <sscanf@plt>
test   %rax,%rax
jle    1420 <main+0x250>
mov    0x20(%rbx),%rdi
add    $0x2,%rdi
lea    0xe1d(%rip),%rsi
lea    0xf(%rsp),%rdx
xor    %eax,%eax
call   10a0 <sscanf@plt>
test   %rax,%rax
jle    1441 <main+0x271>
mov    0x10(%rsp),%rsi
movzbl 0xf(%rsp),%edx
mov    %rbp,%rdi
call   1090 <write_bytes@plt>
jmp    1363 <main+0x193>
mov    0x18(%rbx),%rdi
lea    0xd53(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   10a0 <sscanf@plt>
test   %rax,%rax
jle    1462 <main+0x292>
mov    0x18(%rsp),%rsi
mov    0x10(%rsp),%edx
mov    %rbp,%rdi
call   1040 <read_bytes@plt>
xor    %eax,%eax
call   10e0 <getpagesize@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   10b0 <munmap@plt>
mov    %r14d,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rdi
call   10c0 <usage@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    (%rbx),%rdi
call   10c0 <usage@plt>
mov    0x2c1e(%rip),%rax
mov    (%rax),%edi
lea    0xc51(%rip),%rsi
lea    0xc4e(%rip),%rdx
jmp    1481 <main+0x2b1>
mov    (%rbx),%rdi
call   10c0 <usage@plt>
mov    0x2bfa(%rip),%rax
mov    (%rax),%edi
lea    0xc2d(%rip),%rsi
lea    0xc55(%rip),%rdx
jmp    1481 <main+0x2b1>
mov    0x2bde(%rip),%rax
mov    (%rax),%edi
lea    0xc11(%rip),%rsi
lea    0xc79(%rip),%rdx
jmp    1481 <main+0x2b1>
mov    (%rbx),%rdi
call   10c0 <usage@plt>
mov    0x2bba(%rip),%rax
mov    (%rax),%edi
lea    0xbed(%rip),%rsi
lea    0xcb3(%rip),%rdx
jmp    1481 <main+0x2b1>
mov    (%rbx),%rdi
call   10c0 <usage@plt>
mov    0x2b99(%rip),%rax
mov    (%rax),%edi
lea    0xbcc(%rip),%rsi
lea    0xca8(%rip),%rdx
jmp    1481 <main+0x2b1>
mov    (%rbx),%rdi
call   10c0 <usage@plt>
mov    0x2b78(%rip),%rax
mov    (%rax),%edi
lea    0xbab(%rip),%rsi
lea    0xccd(%rip),%rdx
jmp    1481 <main+0x2b1>
mov    (%rbx),%rdi
call   10c0 <usage@plt>
mov    0x2b57(%rip),%rax
mov    (%rax),%edi
lea    0xb8a(%rip),%rsi
lea    0xc14(%rip),%rdx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%ms\00"
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [37 x i8] c"\0AFailed to read command (read/write)\00"
@.str.3 = [6 x i8] c"%10lx\00"
@.str.4 = [64 x i8] c"\0AFailed to read address (must be hexadecimal, prefixed with 0x)\00"
@.str.5 = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@.str.6 = [24 x i8] c"Failed to open /dev/mem\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.7 = [5 x i8] c"read\00"
@.str.8 = [5 x i8] c"%10u\00"
@.str.9 = [54 x i8] c"\0AFailed to read count (must be decimal integer value)\00"
@.str.10 = [6 x i8] c"write\00"
@.str.11 = [22 x i8] c"\0ANot enough arguments\00"
@.str.12 = [63 x i8] c"\0AFailed to read offset (must be hexadecimal, prefixed with 0x)\00"
@.str.13 = [7 x i8] c"%02hhx\00"
@.str.14 = [62 x i8] c"\0AFailed to read value (must be hexadecimal, prefixed with 0x)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
%11 = alloca i8
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 4
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @usage(i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i64 (i8*, i8*, ...) @sscanf(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %7)
%26 = icmp sle i64 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %21
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 @usage(i8* %30)
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %21
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i64 (i8*, i8*, ...) @sscanf(i8* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64* %9)
%40 = icmp sle i64 %39, 0
br i1 %40, label %41, label %49
41: ; preds = %35
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = call i32 @usage(i8* %44)
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %35
%50 = load i32, i32* @O_RDWR
%51 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %50)
store i32 %51, i32* %8
%52 = load i32, i32* %8
%53 = icmp sle i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %49
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %49
%59 = call i32 (...) @getpagesize()
%60 = load i32, i32* @PROT_READ
%61 = load i32, i32* @PROT_WRITE
%62 = or i32 %60, %61
%63 = load i32, i32* @MAP_SHARED
%64 = load i32, i32* %8
%65 = load i64, i64* %9
%66 = trunc i64 %65 to i32
%67 = call i8* @mmap(i32* null, i32 %59, i32 %62, i32 %63, i32 %64, i32 %66)
store i8* %67, i8** %6
%68 = load i8*, i8** %6
%69 = load i8*, i8** @MAP_FAILED
%70 = icmp ne i8* %68, %69
%71 = zext i1 %70 to i32
%72 = call i32 @assert(i32 %71)
%73 = load i8*, i8** %7
%74 = call i32 @strncmp(i8* %73, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 4)
%75 = icmp ne i32 %74, 0
br i1 %75, label %95, label %76
76: ; preds = %58
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 3
%79 = load i8*, i8** %78
%80 = call i64 (i8*, i8*, ...) @sscanf(i8* %79, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32* %10)
%81 = icmp sle i64 %80, 0
br i1 %81, label %82, label %90
82: ; preds = %76
%83 = load i8**, i8*** %5
%84 = getelementptr inbounds i8*, i8** %83, i64 0
%85 = load i8*, i8** %84
%86 = call i32 @usage(i8* %85)
%87 = load i32, i32* @stderr
%88 = call i32 @fprintf(i32 %87, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.9, i64 0, i64 0))
%89 = call i32 @exit(i32 1)
unreachable
90: ; preds = %76
%91 = load i8*, i8** %6
%92 = load i64, i64* %9
%93 = load i32, i32* %10
%94 = call i32 @read_bytes(i8* %91, i64 %92, i32 %93)
br label %151
95: ; preds = %58
%96 = load i8*, i8** %7
%97 = call i32 @strncmp(i8* %96, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i32 5)
%98 = icmp ne i32 %97, 0
br i1 %98, label %144, label %99
99: ; preds = %95
%100 = load i32, i32* %4
%101 = icmp ne i32 %100, 5
br i1 %101, label %102, label %110
102: ; preds = %99
%103 = load i8**, i8*** %5
%104 = getelementptr inbounds i8*, i8** %103, i64 0
%105 = load i8*, i8** %104
%106 = call i32 @usage(i8* %105)
%107 = load i32, i32* @stderr
%108 = call i32 @fprintf(i32 %107, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0))
%109 = call i32 @exit(i32 1)
unreachable
110: ; preds = %99
%111 = load i8**, i8*** %5
%112 = getelementptr inbounds i8*, i8** %111, i64 3
%113 = load i8*, i8** %112
%114 = call i64 (i8*, i8*, ...) @sscanf(i8* %113, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64* %12)
%115 = icmp sle i64 %114, 0
br i1 %115, label %116, label %124
116: ; preds = %110
%117 = load i8**, i8*** %5
%118 = getelementptr inbounds i8*, i8** %117, i64 0
%119 = load i8*, i8** %118
%120 = call i32 @usage(i8* %119)
%121 = load i32, i32* @stderr
%122 = call i32 @fprintf(i32 %121, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.12, i64 0, i64 0))
%123 = call i32 @exit(i32 1)
unreachable
124: ; preds = %110
%125 = load i8**, i8*** %5
%126 = getelementptr inbounds i8*, i8** %125, i64 4
%127 = load i8*, i8** %126
%128 = getelementptr inbounds i8, i8* %127, i64 2
%129 = call i64 (i8*, i8*, ...) @sscanf(i8* %128, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), i8* %11)
%130 = icmp sle i64 %129, 0
br i1 %130, label %131, label %139
131: ; preds = %124
%132 = load i8**, i8*** %5
%133 = getelementptr inbounds i8*, i8** %132, i64 0
%134 = load i8*, i8** %133
%135 = call i32 @usage(i8* %134)
%136 = load i32, i32* @stderr
%137 = call i32 @fprintf(i32 %136, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.14, i64 0, i64 0))
%138 = call i32 @exit(i32 1)
unreachable
139: ; preds = %124
%140 = load i8*, i8** %6
%141 = load i64, i64* %12
%142 = load i8, i8* %11
%143 = call i32 @write_bytes(i8* %140, i64 %141, i8 zeroext %142)
br label %150
144: ; preds = %95
%145 = load i8**, i8*** %5
%146 = getelementptr inbounds i8*, i8** %145, i64 0
%147 = load i8*, i8** %146
%148 = call i32 @usage(i8* %147)
%149 = call i32 @exit(i32 1)
unreachable
150: ; preds = %139
br label %151
151: ; preds = %150, %90
%152 = load i8*, i8** %6
%153 = call i32 (...) @getpagesize()
%154 = call i32 @munmap(i8* %152, i32 %153)
%155 = load i32, i32* %8
%156 = call i32 @close(i32 %155)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%ms\00"
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [37 x i8] c"\0AFailed to read command (read/write)\00"
@.str.3 = [6 x i8] c"%10lx\00"
@.str.4 = [64 x i8] c"\0AFailed to read address (must be hexadecimal, prefixed with 0x)\00"
@.str.5 = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@.str.6 = [24 x i8] c"Failed to open /dev/mem\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.7 = [5 x i8] c"read\00"
@.str.8 = [5 x i8] c"%10u\00"
@.str.9 = [54 x i8] c"\0AFailed to read count (must be decimal integer value)\00"
@.str.10 = [6 x i8] c"write\00"
@.str.11 = [22 x i8] c"\0ANot enough arguments\00"
@.str.12 = [63 x i8] c"\0AFailed to read offset (must be hexadecimal, prefixed with 0x)\00"
@.str.13 = [7 x i8] c"%02hhx\00"
@.str.14 = [62 x i8] c"\0AFailed to read value (must be hexadecimal, prefixed with 0x)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8
%7 = alloca i64
%8 = bitcast i8** %3 to i8*
%9 = bitcast i64* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = icmp slt i32 %0, 4
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 @usage(i8* %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = call i64 (i8*, i8*, ...) @sscanf(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %3)
%20 = icmp slt i64 %19, 1
br i1 %20, label %21, label %27
21: ; preds = %16
%22 = load i8*, i8** %1
%23 = call i32 @usage(i8* %22)
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %16
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = call i64 (i8*, i8*, ...) @sscanf(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64* %4)
%31 = icmp slt i64 %30, 1
br i1 %31, label %32, label %38
32: ; preds = %27
%33 = load i8*, i8** %1
%34 = call i32 @usage(i8* %33)
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %27
%39 = load i32, i32* @O_RDWR
%40 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %39)
%41 = icmp slt i32 %40, 1
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %38
%47 = call i32 (...) @getpagesize()
%48 = load i32, i32* @PROT_READ
%49 = load i32, i32* @PROT_WRITE
%50 = or i32 %49, %48
%51 = load i32, i32* @MAP_SHARED
%52 = load i64, i64* %4
%53 = trunc i64 %52 to i32
%54 = call i8* @mmap(i32* null, i32 %47, i32 %50, i32 %51, i32 %40, i32 %53)
%55 = load i8*, i8** @MAP_FAILED
%56 = icmp ne i8* %54, %55
%57 = zext i1 %56 to i32
%58 = call i32 @assert(i32 %57)
%59 = load i8*, i8** %3
%60 = call i32 @strncmp(i8* %59, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 4)
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %77
62: ; preds = %46
%63 = getelementptr inbounds i8*, i8** %1, i64 3
%64 = load i8*, i8** %63
%65 = call i64 (i8*, i8*, ...) @sscanf(i8* %64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32* %5)
%66 = icmp slt i64 %65, 1
br i1 %66, label %67, label %73
67: ; preds = %62
%68 = load i8*, i8** %1
%69 = call i32 @usage(i8* %68)
%70 = load i32, i32* @stderr
%71 = call i32 @fprintf(i32 %70, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.9, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %62
%74 = load i64, i64* %4
%75 = load i32, i32* %5
%76 = call i32 @read_bytes(i8* %54, i64 %74, i32 %75)
br label %121
77: ; preds = %46
%78 = load i8*, i8** %3
%79 = call i32 @strncmp(i8* %78, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i32 5)
%80 = icmp eq i32 %79, 0
br i1 %80, label %81, label %117
81: ; preds = %77
%82 = bitcast i64* %7 to i8*
%83 = icmp eq i32 %0, 5
br i1 %83, label %90, label %84
84: ; preds = %81
%85 = load i8*, i8** %1
%86 = call i32 @usage(i8* %85)
%87 = load i32, i32* @stderr
%88 = call i32 @fprintf(i32 %87, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0))
%89 = call i32 @exit(i32 1)
unreachable
90: ; preds = %81
%91 = getelementptr inbounds i8*, i8** %1, i64 3
%92 = load i8*, i8** %91
%93 = call i64 (i8*, i8*, ...) @sscanf(i8* %92, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64* %7)
%94 = icmp slt i64 %93, 1
br i1 %94, label %95, label %101
95: ; preds = %90
%96 = load i8*, i8** %1
%97 = call i32 @usage(i8* %96)
%98 = load i32, i32* @stderr
%99 = call i32 @fprintf(i32 %98, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.12, i64 0, i64 0))
%100 = call i32 @exit(i32 1)
unreachable
101: ; preds = %90
%102 = getelementptr inbounds i8*, i8** %1, i64 4
%103 = load i8*, i8** %102
%104 = getelementptr inbounds i8, i8* %103, i64 2
%105 = call i64 (i8*, i8*, ...) @sscanf(i8* %104, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), i8* %6)
%106 = icmp slt i64 %105, 1
br i1 %106, label %107, label %113
107: ; preds = %101
%108 = load i8*, i8** %1
%109 = call i32 @usage(i8* %108)
%110 = load i32, i32* @stderr
%111 = call i32 @fprintf(i32 %110, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.14, i64 0, i64 0))
%112 = call i32 @exit(i32 1)
unreachable
113: ; preds = %101
%114 = load i64, i64* %7
%115 = load i8, i8* %6
%116 = call i32 @write_bytes(i8* %54, i64 %114, i8 zeroext %115)
br label %121
117: ; preds = %77
%118 = load i8*, i8** %1
%119 = call i32 @usage(i8* %118)
%120 = call i32 @exit(i32 1)
unreachable
121: ; preds = %113, %73
%122 = call i32 (...) @getpagesize()
%123 = call i32 @munmap(i8* %54, i32 %122)
%124 = call i32 @close(i32 %40)
ret i32 0
}