#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 uint8_t;
typedef int uint16_t;
typedef int int16_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ _SC_PAGESIZE;
int /*<<< orphan*/ memcpy(char *, void volatile *, int);
void *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ munmap(void volatile *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int);
int sysconf(int /*<<< orphan*/);
int /*<<< orphan*/ usleep(int);
int main() {
  int fd, i;
  int position, limit, offset;
  int16_t value[2];
  volatile void *cfg, *sts, *gpio_n, *gpio_p, *ram;
  char buffer[32768];
  if ((fd = open("/dev/mem", O_RDWR)) < 0) {
    perror("open");
    return EXIT_FAILURE;
  }
  cfg = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ | PROT_WRITE, MAP_SHARED,
             fd, 0x40000000);
  sts = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ | PROT_WRITE, MAP_SHARED,
             fd, 0x40001000);
  gpio_n = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ | PROT_WRITE, MAP_SHARED,
                fd, 0x40002000);
  gpio_p = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ | PROT_WRITE, MAP_SHARED,
                fd, 0x40003000);
  ram = mmap(NULL, 16 * sysconf(_SC_PAGESIZE), PROT_READ | PROT_WRITE,
             MAP_SHARED, fd, 0x40010000);
  *((uint16_t *)(cfg + 0)) &= ~3;
  *((uint16_t *)(cfg + 2)) = 0;
  *((uint16_t *)(cfg + 4)) = 1;
  *((uint16_t *)(cfg + 6)) = 1;
  *((uint16_t *)(cfg + 8)) = 8192 - 1;
  *((uint16_t *)(cfg + 10)) = 10 - 1;
  *((uint8_t *)(cfg + 12)) |= 1;
  *((uint8_t *)(gpio_n + 4)) &= ~1;
  *((uint8_t *)(gpio_n + 0)) |= 1;
  *((uint8_t *)(gpio_p + 4)) &= ~1;
  *((uint8_t *)(gpio_p + 0)) |= 1;
  *((uint16_t *)(cfg + 0)) |= 3;
  limit = 8192;
  while (1) {
    position = *((uint16_t *)(sts + 2));
    if ((limit > 0 && position > limit) || (limit == 0 && position < 8192)) {
      offset = limit > 0 ? 0 : 32768;
      limit = limit > 0 ? 0 : 8192;
      memcpy(buffer, ram + offset, 32768);
      for (i = 0; i < 8192; ++i) {
        value[0] = *((int16_t *)(buffer + 4 * i + 0));
        value[1] = *((int16_t *)(buffer + 4 * i + 2));
        printf("%5d %5d\n", value[0], value[1]);
      }
      return EXIT_SUCCESS;
    } else {
      usleep(100);
    }
  }
  munmap(cfg, sysconf(_SC_PAGESIZE));
  munmap(sts, sysconf(_SC_PAGESIZE));
  munmap(gpio_n, sysconf(_SC_PAGESIZE));
  munmap(gpio_p, sysconf(_SC_PAGESIZE));
  munmap(ram, sysconf(_SC_PAGESIZE));
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8050,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
lea    0xe6e(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11c0 <main+0x50>
lea    0xe5f(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    148f <main+0x31f>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %eax,%esi
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
mov    0x2dd8(%rip),%rax
or     (%rax),%edx
mov    0x2dff(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x40000000,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %eax,%esi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
mov    0x2d96(%rip),%rax
or     (%rax),%edx
mov    0x2dbd(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x40001000,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %eax,%esi
mov    0x2d9d(%rip),%rax
mov    (%rax),%edx
mov    0x2d54(%rip),%rax
or     (%rax),%edx
mov    0x2d7b(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x40002000,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x38(%rbp)
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %eax,%esi
mov    0x2d5b(%rip),%rax
mov    (%rax),%edx
mov    0x2d12(%rip),%rax
or     (%rax),%edx
mov    0x2d39(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x40003000,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x40(%rbp)
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %eax,%esi
shl    $0x4,%esi
mov    0x2d16(%rip),%rax
mov    (%rax),%edx
mov    0x2ccd(%rip),%rax
or     (%rax),%edx
mov    0x2cf4(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x40010000,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
and    $0xfffffffc,%ecx
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,0x2(%rax)
mov    -0x28(%rbp),%rax
movl   $0x1,0x4(%rax)
mov    -0x28(%rbp),%rax
movl   $0x1,0x6(%rax)
mov    -0x28(%rbp),%rax
movl   $0x1fff,0x8(%rax)
mov    -0x28(%rbp),%rax
movl   $0x9,0xa(%rax)
mov    -0x28(%rbp),%rax
mov    0xc(%rax),%ecx
or     $0x1,%ecx
mov    %ecx,0xc(%rax)
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%ecx
and    $0xfffffffe,%ecx
mov    %ecx,0x4(%rax)
mov    -0x38(%rbp),%rax
mov    (%rax),%ecx
or     $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%ecx
and    $0xfffffffe,%ecx
mov    %ecx,0x4(%rax)
mov    -0x40(%rbp),%rax
mov    (%rax),%ecx
or     $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
or     $0x3,%ecx
mov    %ecx,(%rax)
movl   $0x2000,-0x14(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2(%rax),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    13be <main+0x24e>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     13d5 <main+0x265>
cmpl   $0x0,-0x14(%rbp)
jne    1480 <main+0x310>
cmpl   $0x2000,-0x10(%rbp)
jge    1480 <main+0x310>
mov    -0x14(%rbp),%edx
mov    $0x8000,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovg  %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edx
mov    $0x2000,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovg  %ecx,%eax
mov    %eax,-0x14(%rbp)
lea    -0x8050(%rbp),%rdi
mov    -0x48(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    $0x8000,%edx
call   1050 <memcpy@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x2000,-0xc(%rbp)
jge    146f <main+0x2ff>
mov    -0xc(%rbp),%eax
shl    $0x2,%eax
cltq
mov    -0x8050(%rbp,%rax,1),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x2,%eax
cltq
mov    -0x804e(%rbp,%rax,1),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xbb2(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    141e <main+0x2ae>
mov    0x2b3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    148f <main+0x31f>
mov    $0x64,%edi
call   1090 <usleep@plt>
jmp    139e <main+0x22e>
mov    -0x4(%rbp),%eax
add    $0x8050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8008,%rsp
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
lea    0xe6f(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1371 <main+0x201>
mov    %eax,%r14d
mov    0x2e28(%rip),%r13
mov    0x0(%r13),%edi
call   1080 <sysconf@plt>
mov    0x2e40(%rip),%r15
mov    0x2df9(%rip),%rsi
mov    (%rsi),%edx
mov    %rsi,%r12
or     (%r15),%edx
mov    0x2e1a(%rip),%rbp
mov    0x0(%rbp),%ecx
xor    %edi,%edi
mov    %eax,%esi
mov    %r14d,%r8d
mov    $0x40000000,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
mov    0x0(%r13),%edi
call   1080 <sysconf@plt>
mov    (%r12),%edx
or     (%r15),%edx
mov    0x0(%rbp),%ecx
xor    %edi,%edi
mov    %eax,%esi
mov    %r14d,%r8d
mov    $0x40001000,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbp
mov    0x0(%r13),%edi
call   1080 <sysconf@plt>
mov    (%r12),%edx
mov    %r12,%r13
or     (%r15),%edx
mov    %r15,%r12
mov    0x2dbd(%rip),%rcx
mov    (%rcx),%ecx
xor    %edi,%edi
mov    %eax,%esi
mov    %r14d,%r8d
mov    $0x40002000,%r9d
call   1030 <mmap@plt>
mov    %rax,%r15
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    0x0(%r13),%edx
or     (%r12),%edx
mov    0x2d89(%rip),%rcx
mov    (%rcx),%ecx
xor    %edi,%edi
mov    %eax,%esi
mov    %r14d,%r8d
mov    $0x40003000,%r9d
call   1030 <mmap@plt>
mov    %rax,%r12
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
shl    $0x4,%eax
mov    0x0(%r13),%edx
mov    0x2d66(%rip),%rcx
or     (%rcx),%edx
mov    0x2d4d(%rip),%rcx
mov    (%rcx),%ecx
xor    %edi,%edi
mov    %eax,%esi
mov    %r14d,%r8d
mov    $0x40010000,%r9d
call   1030 <mmap@plt>
andb   $0xfc,(%rbx)
movl   $0x0,0x2(%rbx)
movl   $0x1,0x4(%rbx)
movl   $0x1,0x6(%rbx)
movl   $0x1fff,0x8(%rbx)
movl   $0x9,0xa(%rbx)
orb    $0x1,0xc(%rbx)
andb   $0xfe,0x4(%r15)
orb    $0x1,(%r15)
andb   $0xfe,0x4(%r12)
orb    $0x1,(%r12)
orb    $0x3,(%rbx)
mov    %rax,%rbx
cmpl   $0x2000,0x2(%rbp)
jg     1313 <main+0x1a3>
nopl   0x0(%rax)
mov    $0x64,%edi
call   1090 <usleep@plt>
cmpl   $0x2000,0x2(%rbp)
jle    1300 <main+0x190>
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    $0x8000,%edx
call   1050 <memcpy@plt>
xor    %ebp,%ebp
lea    0xce2(%rip),%rbx
mov    0x2c7d(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rsp,%rbp,4),%esi
mov    0x2(%rsp,%rbp,4),%edx
mov    %rbx,%rdi
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    $0x2000,%rbp
jne    1340 <main+0x1d0>
mov    (%r14),%eax
add    $0x8008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc91(%rip),%rdi
call   1070 <perror@plt>
mov    0x2c3c(%rip),%r14
jmp    135c <main+0x1ec>

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@_SC_PAGESIZE = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.2 = [9 x i8] c"%5d %5d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [2 x i32]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca [32768 x i8]
store i32 0, i32* %1
%14 = load i32, i32* @O_RDWR
%15 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 %15, i32* %2
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %1
br label %179
20: ; preds = %0
%21 = load i32, i32* @_SC_PAGESIZE
%22 = call i32 @sysconf(i32 %21)
%23 = load i32, i32* @PROT_READ
%24 = load i32, i32* @PROT_WRITE
%25 = or i32 %23, %24
%26 = load i32, i32* @MAP_SHARED
%27 = load i32, i32* %2
%28 = call i8* @mmap(i32* null, i32 %22, i32 %25, i32 %26, i32 %27, i32 1073741824)
store i8* %28, i8** %8
%29 = load i32, i32* @_SC_PAGESIZE
%30 = call i32 @sysconf(i32 %29)
%31 = load i32, i32* @PROT_READ
%32 = load i32, i32* @PROT_WRITE
%33 = or i32 %31, %32
%34 = load i32, i32* @MAP_SHARED
%35 = load i32, i32* %2
%36 = call i8* @mmap(i32* null, i32 %30, i32 %33, i32 %34, i32 %35, i32 1073745920)
store i8* %36, i8** %9
%37 = load i32, i32* @_SC_PAGESIZE
%38 = call i32 @sysconf(i32 %37)
%39 = load i32, i32* @PROT_READ
%40 = load i32, i32* @PROT_WRITE
%41 = or i32 %39, %40
%42 = load i32, i32* @MAP_SHARED
%43 = load i32, i32* %2
%44 = call i8* @mmap(i32* null, i32 %38, i32 %41, i32 %42, i32 %43, i32 1073750016)
store i8* %44, i8** %10
%45 = load i32, i32* @_SC_PAGESIZE
%46 = call i32 @sysconf(i32 %45)
%47 = load i32, i32* @PROT_READ
%48 = load i32, i32* @PROT_WRITE
%49 = or i32 %47, %48
%50 = load i32, i32* @MAP_SHARED
%51 = load i32, i32* %2
%52 = call i8* @mmap(i32* null, i32 %46, i32 %49, i32 %50, i32 %51, i32 1073754112)
store i8* %52, i8** %11
%53 = load i32, i32* @_SC_PAGESIZE
%54 = call i32 @sysconf(i32 %53)
%55 = mul nsw i32 16, %54
%56 = load i32, i32* @PROT_READ
%57 = load i32, i32* @PROT_WRITE
%58 = or i32 %56, %57
%59 = load i32, i32* @MAP_SHARED
%60 = load i32, i32* %2
%61 = call i8* @mmap(i32* null, i32 %55, i32 %58, i32 %59, i32 %60, i32 1073807360)
store i8* %61, i8** %12
%62 = load i8*, i8** %8
%63 = getelementptr i8, i8* %62, i64 0
%64 = bitcast i8* %63 to i32*
%65 = load i32, i32* %64
%66 = and i32 %65, -4
store i32 %66, i32* %64
%67 = load i8*, i8** %8
%68 = getelementptr i8, i8* %67, i64 2
%69 = bitcast i8* %68 to i32*
store i32 0, i32* %69
%70 = load i8*, i8** %8
%71 = getelementptr i8, i8* %70, i64 4
%72 = bitcast i8* %71 to i32*
store i32 1, i32* %72
%73 = load i8*, i8** %8
%74 = getelementptr i8, i8* %73, i64 6
%75 = bitcast i8* %74 to i32*
store i32 1, i32* %75
%76 = load i8*, i8** %8
%77 = getelementptr i8, i8* %76, i64 8
%78 = bitcast i8* %77 to i32*
store i32 8191, i32* %78
%79 = load i8*, i8** %8
%80 = getelementptr i8, i8* %79, i64 10
%81 = bitcast i8* %80 to i32*
store i32 9, i32* %81
%82 = load i8*, i8** %8
%83 = getelementptr i8, i8* %82, i64 12
%84 = bitcast i8* %83 to i32*
%85 = load i32, i32* %84
%86 = or i32 %85, 1
store i32 %86, i32* %84
%87 = load i8*, i8** %10
%88 = getelementptr i8, i8* %87, i64 4
%89 = bitcast i8* %88 to i32*
%90 = load i32, i32* %89
%91 = and i32 %90, -2
store i32 %91, i32* %89
%92 = load i8*, i8** %10
%93 = getelementptr i8, i8* %92, i64 0
%94 = bitcast i8* %93 to i32*
%95 = load i32, i32* %94
%96 = or i32 %95, 1
store i32 %96, i32* %94
%97 = load i8*, i8** %11
%98 = getelementptr i8, i8* %97, i64 4
%99 = bitcast i8* %98 to i32*
%100 = load i32, i32* %99
%101 = and i32 %100, -2
store i32 %101, i32* %99
%102 = load i8*, i8** %11
%103 = getelementptr i8, i8* %102, i64 0
%104 = bitcast i8* %103 to i32*
%105 = load i32, i32* %104
%106 = or i32 %105, 1
store i32 %106, i32* %104
%107 = load i8*, i8** %8
%108 = getelementptr i8, i8* %107, i64 0
%109 = bitcast i8* %108 to i32*
%110 = load i32, i32* %109
%111 = or i32 %110, 3
store i32 %111, i32* %109
store i32 8192, i32* %5
br label %112
112: ; preds = %20, %178
%113 = load i8*, i8** %9
%114 = getelementptr i8, i8* %113, i64 2
%115 = bitcast i8* %114 to i32*
%116 = load i32, i32* %115
store i32 %116, i32* %4
%117 = load i32, i32* %5
%118 = icmp sgt i32 %117, 0
br i1 %118, label %119, label %123
119: ; preds = %112
%120 = load i32, i32* %4
%121 = load i32, i32* %5
%122 = icmp sgt i32 %120, %121
br i1 %122, label %129, label %123
123: ; preds = %119, %112
%124 = load i32, i32* %5
%125 = icmp eq i32 %124, 0
br i1 %125, label %126, label %176
126: ; preds = %123
%127 = load i32, i32* %4
%128 = icmp slt i32 %127, 8192
br i1 %128, label %129, label %176
129: ; preds = %126, %119
%130 = load i32, i32* %5
%131 = icmp sgt i32 %130, 0
%132 = zext i1 %131 to i64
%133 = select i1 %131, i32 0, i32 32768
store i32 %133, i32* %6
%134 = load i32, i32* %5
%135 = icmp sgt i32 %134, 0
%136 = zext i1 %135 to i64
%137 = select i1 %135, i32 0, i32 8192
store i32 %137, i32* %5
%138 = getelementptr inbounds [32768 x i8], [32768 x i8]* %13, i64 0, i64 0
%139 = load i8*, i8** %12
%140 = load i32, i32* %6
%141 = sext i32 %140 to i64
%142 = getelementptr i8, i8* %139, i64 %141
%143 = call i32 @memcpy(i8* %138, i8* %142, i32 32768)
store i32 0, i32* %3
br label %144
144: ; preds = %171, %129
%145 = load i32, i32* %3
%146 = icmp slt i32 %145, 8192
br i1 %146, label %147, label %174
147: ; preds = %144
%148 = getelementptr inbounds [32768 x i8], [32768 x i8]* %13, i64 0, i64 0
%149 = load i32, i32* %3
%150 = mul nsw i32 4, %149
%151 = sext i32 %150 to i64
%152 = getelementptr inbounds i8, i8* %148, i64 %151
%153 = getelementptr inbounds i8, i8* %152, i64 0
%154 = bitcast i8* %153 to i32*
%155 = load i32, i32* %154
%156 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
store i32 %155, i32* %156
%157 = getelementptr inbounds [32768 x i8], [32768 x i8]* %13, i64 0, i64 0
%158 = load i32, i32* %3
%159 = mul nsw i32 4, %158
%160 = sext i32 %159 to i64
%161 = getelementptr inbounds i8, i8* %157, i64 %160
%162 = getelementptr inbounds i8, i8* %161, i64 2
%163 = bitcast i8* %162 to i32*
%164 = load i32, i32* %163
%165 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
store i32 %164, i32* %165
%166 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%167 = load i32, i32* %166
%168 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%169 = load i32, i32* %168
%170 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %167, i32 %169)
br label %171
171: ; preds = %147
%172 = load i32, i32* %3
%173 = add nsw i32 %172, 1
store i32 %173, i32* %3
br label %144
174: ; preds = %144
%175 = load i32, i32* @EXIT_SUCCESS
store i32 %175, i32* %1
br label %179
176: ; preds = %126, %123
%177 = call i32 @usleep(i32 100)
br label %178
178: ; preds = %176
br label %112
179: ; preds = %174, %17
%180 = load i32, i32* %1
ret i32 %180
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@_SC_PAGESIZE = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.2 = [9 x i8] c"%5d %5d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [32768 x i8]
%2 = getelementptr inbounds [32768 x i8], [32768 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %100
8: ; preds = %0
%9 = load i32, i32* @_SC_PAGESIZE
%10 = tail call i32 @sysconf(i32 %9)
%11 = load i32, i32* @PROT_READ
%12 = load i32, i32* @PROT_WRITE
%13 = or i32 %12, %11
%14 = load i32, i32* @MAP_SHARED
%15 = tail call i8* @mmap(i32* null, i32 %10, i32 %13, i32 %14, i32 %4, i32 1073741824)
%16 = load i32, i32* @_SC_PAGESIZE
%17 = tail call i32 @sysconf(i32 %16)
%18 = load i32, i32* @PROT_READ
%19 = load i32, i32* @PROT_WRITE
%20 = or i32 %19, %18
%21 = load i32, i32* @MAP_SHARED
%22 = tail call i8* @mmap(i32* null, i32 %17, i32 %20, i32 %21, i32 %4, i32 1073745920)
%23 = load i32, i32* @_SC_PAGESIZE
%24 = tail call i32 @sysconf(i32 %23)
%25 = load i32, i32* @PROT_READ
%26 = load i32, i32* @PROT_WRITE
%27 = or i32 %26, %25
%28 = load i32, i32* @MAP_SHARED
%29 = tail call i8* @mmap(i32* null, i32 %24, i32 %27, i32 %28, i32 %4, i32 1073750016)
%30 = load i32, i32* @_SC_PAGESIZE
%31 = tail call i32 @sysconf(i32 %30)
%32 = load i32, i32* @PROT_READ
%33 = load i32, i32* @PROT_WRITE
%34 = or i32 %33, %32
%35 = load i32, i32* @MAP_SHARED
%36 = tail call i8* @mmap(i32* null, i32 %31, i32 %34, i32 %35, i32 %4, i32 1073754112)
%37 = load i32, i32* @_SC_PAGESIZE
%38 = tail call i32 @sysconf(i32 %37)
%39 = shl nsw i32 %38, 4
%40 = load i32, i32* @PROT_READ
%41 = load i32, i32* @PROT_WRITE
%42 = or i32 %41, %40
%43 = load i32, i32* @MAP_SHARED
%44 = tail call i8* @mmap(i32* null, i32 %39, i32 %42, i32 %43, i32 %4, i32 1073807360)
%45 = bitcast i8* %15 to i32*
%46 = load i32, i32* %45
%47 = and i32 %46, -4
store i32 %47, i32* %45
%48 = getelementptr i8, i8* %15, i64 2
%49 = bitcast i8* %48 to i32*
store i32 0, i32* %49
%50 = getelementptr i8, i8* %15, i64 4
%51 = bitcast i8* %50 to i32*
store i32 1, i32* %51
%52 = getelementptr i8, i8* %15, i64 6
%53 = bitcast i8* %52 to i32*
store i32 1, i32* %53
%54 = getelementptr i8, i8* %15, i64 8
%55 = bitcast i8* %54 to i32*
store i32 8191, i32* %55
%56 = getelementptr i8, i8* %15, i64 10
%57 = bitcast i8* %56 to i32*
store i32 9, i32* %57
%58 = getelementptr i8, i8* %15, i64 12
%59 = bitcast i8* %58 to i32*
%60 = load i32, i32* %59
%61 = or i32 %60, 1
store i32 %61, i32* %59
%62 = getelementptr i8, i8* %29, i64 4
%63 = bitcast i8* %62 to i32*
%64 = load i32, i32* %63
%65 = and i32 %64, -2
store i32 %65, i32* %63
%66 = bitcast i8* %29 to i32*
%67 = load i32, i32* %66
%68 = or i32 %67, 1
store i32 %68, i32* %66
%69 = getelementptr i8, i8* %36, i64 4
%70 = bitcast i8* %69 to i32*
%71 = load i32, i32* %70
%72 = and i32 %71, -2
store i32 %72, i32* %70
%73 = bitcast i8* %36 to i32*
%74 = load i32, i32* %73
%75 = or i32 %74, 1
store i32 %75, i32* %73
%76 = load i32, i32* %45
%77 = or i32 %76, 3
store i32 %77, i32* %45
%78 = getelementptr i8, i8* %22, i64 2
%79 = bitcast i8* %78 to i32*
%80 = load i32, i32* %79
%81 = icmp sgt i32 %80, 8192
br i1 %81, label %82, label %96
82: ; preds = %96, %8
%83 = call i32 @memcpy(i8* %2, i8* %44, i32 32768)
br label %84
84: ; preds = %82, %84
%85 = phi i64 [ 0, %82 ], [ %94, %84 ]
%86 = shl nuw nsw i64 %85, 2
%87 = getelementptr inbounds [32768 x i8], [32768 x i8]* %1, i64 0, i64 %86
%88 = bitcast i8* %87 to i32*
%89 = load i32, i32* %88
%90 = getelementptr inbounds i8, i8* %87, i64 2
%91 = bitcast i8* %90 to i32*
%92 = load i32, i32* %91
%93 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %89, i32 %92)
%94 = add nuw nsw i64 %85, 1
%95 = icmp eq i64 %94, 8192
br i1 %95, label %100, label %84
96: ; preds = %8, %96
%97 = tail call i32 @usleep(i32 100)
%98 = load i32, i32* %79
%99 = icmp sgt i32 %98, 8192
br i1 %99, label %82, label %96
100: ; preds = %84, %6
%101 = phi i32* [ @EXIT_FAILURE, %6 ], [ @EXIT_SUCCESS, %84 ]
%102 = load i32, i32* %101
ret i32 %102
}