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

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ _SC_PAGESIZE;
void *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ sleep(int);
int sysconf(int /*<<< orphan*/);
int main() {
  int fd, i;
  int16_t value[2];
  volatile uint8_t *rst;
  volatile uint32_t *size, *slcr, *axi_hp0;
  volatile void *cfg;
  volatile int16_t *ram;
  if ((fd = open("/dev/mem", O_RDWR)) < 0) {
    perror("open");
    return 1;
  }
  slcr = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ | PROT_WRITE, MAP_SHARED,
              fd, 0xF8000000);
  axi_hp0 = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ | PROT_WRITE,
                 MAP_SHARED, fd, 0xF8008000);
  cfg = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ | PROT_WRITE, MAP_SHARED,
             fd, 0x40000000);
  ram = mmap(NULL, 1024 * sysconf(_SC_PAGESIZE), PROT_READ | PROT_WRITE,
             MAP_SHARED, fd, 0x1E000000);
  slcr[2] = 0xDF0D;
  slcr[144] = 0;
  axi_hp0[0] &= ~1;
  axi_hp0[5] &= ~1;
  rst = ((uint8_t *)(cfg + 0));
  size = ((uint32_t *)(cfg + 4));
  *rst &= ~4;
  *rst |= 4;
  *rst &= ~1;
  *rst |= 1;
  sleep(1);
  *rst &= ~2;
  *size = 1024 * 1024 - 1;
  *rst |= 2;
  sleep(1);
  for (i = 0; i < 1024 * 1024; ++i) {
    value[0] = ram[2 * i + 0];
    value[1] = ram[2 * i + 1];
    printf("%5d %5d\n", value[0], value[1]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11a8 <main+0x48>
lea    0xe72(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13bf <main+0x25f>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %eax,%esi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
mov    0x2df8(%rip),%rax
or     (%rax),%edx
mov    0x2e17(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0xf8000000,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %eax,%esi
mov    0x2df7(%rip),%rax
mov    (%rax),%edx
mov    0x2db6(%rip),%rax
or     (%rax),%edx
mov    0x2dd5(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0xf8008000,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x38(%rbp)
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %eax,%esi
mov    0x2db5(%rip),%rax
mov    (%rax),%edx
mov    0x2d74(%rip),%rax
or     (%rax),%edx
mov    0x2d93(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x40000000,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x40(%rbp)
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %eax,%esi
shl    $0xa,%esi
mov    0x2d70(%rip),%rax
mov    (%rax),%edx
mov    0x2d2f(%rip),%rax
or     (%rax),%edx
mov    0x2d4e(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1e000000,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
movl   $0xdf0d,0x8(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,0x240(%rax)
mov    -0x38(%rbp),%rax
mov    (%rax),%ecx
and    $0xfffffffe,%ecx
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
mov    0x14(%rax),%ecx
and    $0xfffffffe,%ecx
mov    %ecx,0x14(%rax)
mov    -0x40(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x40(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
and    $0xfffffffb,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
or     $0x4,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
and    $0xfffffffe,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
or     $0x1,%ecx
mov    %ecx,(%rax)
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
and    $0xfffffffd,%ecx
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
movl   $0xfffff,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
or     $0x2,%ecx
mov    %ecx,(%rax)
mov    $0x1,%edi
call   1080 <sleep@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x100000,-0xc(%rbp)
jge    13b8 <main+0x258>
mov    -0x48(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x48(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xc69(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    135f <main+0x1ff>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     12de <main+0x17e>
mov    %eax,%ebp
mov    0x2e3f(%rip),%r13
mov    0x0(%r13),%edi
call   1070 <sysconf@plt>
mov    0x2e57(%rip),%rcx
mov    0x2e18(%rip),%r14
mov    (%r14),%edx
or     (%rcx),%edx
mov    %rcx,%rbx
mov    0x2e31(%rip),%r12
mov    (%r12),%ecx
xor    %edi,%edi
mov    %eax,%esi
mov    %ebp,%r8d
mov    $0xf8000000,%r9d
call   1030 <mmap@plt>
mov    %rax,(%rsp)
mov    0x0(%r13),%edi
call   1070 <sysconf@plt>
mov    (%r14),%edx
or     (%rbx),%edx
mov    (%r12),%ecx
mov    %r12,%r15
xor    %edi,%edi
mov    %eax,%esi
mov    %ebp,%r8d
mov    $0xf8008000,%r9d
call   1030 <mmap@plt>
mov    %rax,%r12
mov    0x0(%r13),%edi
call   1070 <sysconf@plt>
mov    (%r14),%edx
or     (%rbx),%edx
mov    (%r15),%ecx
xor    %edi,%edi
mov    %eax,%esi
mov    %ebp,%r8d
mov    $0x40000000,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
mov    0x0(%r13),%edi
call   1070 <sysconf@plt>
shl    $0xa,%eax
mov    (%r14),%edx
mov    0x2dc1(%rip),%rcx
or     (%rcx),%edx
mov    (%r15),%ecx
xor    %edi,%edi
mov    %eax,%esi
mov    %ebp,%r8d
mov    $0x1e000000,%r9d
call   1030 <mmap@plt>
mov    (%rsp),%rcx
movl   $0xdf0d,0x8(%rcx)
movl   $0x0,0x240(%rcx)
andl   $0xfffffffe,(%r12)
andl   $0xfffffffe,0x14(%r12)
andl   $0xfffffffb,(%rbx)
orl    $0x4,(%rbx)
andl   $0xfffffffe,(%rbx)
mov    %rax,%rbp
orl    $0x1,(%rbx)
mov    $0x1,%edi
call   1080 <sleep@plt>
andl   $0xfffffffd,(%rbx)
movl   $0xfffff,0x4(%rbx)
orl    $0x2,(%rbx)
mov    $0x1,%edi
call   1080 <sleep@plt>
lea    0xd69(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp,%rbx,8),%esi
mov    0x4(%rbp,%rbx,8),%edx
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0x100000,%rbx
jne    12b0 <main+0x150>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd24(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%eax
jmp    12cf <main+0x16f>

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@_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"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x i32]
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32*
store i32 0, i32* %1
%11 = load i32, i32* @O_RDWR
%12 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %2
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %121
16: ; preds = %0
%17 = load i32, i32* @_SC_PAGESIZE
%18 = call i32 @sysconf(i32 %17)
%19 = load i32, i32* @PROT_READ
%20 = load i32, i32* @PROT_WRITE
%21 = or i32 %19, %20
%22 = load i32, i32* @MAP_SHARED
%23 = load i32, i32* %2
%24 = call i8* @mmap(i32* null, i32 %18, i32 %21, i32 %22, i32 %23, i32 -134217728)
%25 = bitcast i8* %24 to i32*
store i32* %25, i32** %7
%26 = load i32, i32* @_SC_PAGESIZE
%27 = call i32 @sysconf(i32 %26)
%28 = load i32, i32* @PROT_READ
%29 = load i32, i32* @PROT_WRITE
%30 = or i32 %28, %29
%31 = load i32, i32* @MAP_SHARED
%32 = load i32, i32* %2
%33 = call i8* @mmap(i32* null, i32 %27, i32 %30, i32 %31, i32 %32, i32 -134184960)
%34 = bitcast i8* %33 to i32*
store i32* %34, i32** %8
%35 = load i32, i32* @_SC_PAGESIZE
%36 = call i32 @sysconf(i32 %35)
%37 = load i32, i32* @PROT_READ
%38 = load i32, i32* @PROT_WRITE
%39 = or i32 %37, %38
%40 = load i32, i32* @MAP_SHARED
%41 = load i32, i32* %2
%42 = call i8* @mmap(i32* null, i32 %36, i32 %39, i32 %40, i32 %41, i32 1073741824)
store i8* %42, i8** %9
%43 = load i32, i32* @_SC_PAGESIZE
%44 = call i32 @sysconf(i32 %43)
%45 = mul nsw i32 1024, %44
%46 = load i32, i32* @PROT_READ
%47 = load i32, i32* @PROT_WRITE
%48 = or i32 %46, %47
%49 = load i32, i32* @MAP_SHARED
%50 = load i32, i32* %2
%51 = call i8* @mmap(i32* null, i32 %45, i32 %48, i32 %49, i32 %50, i32 503316480)
%52 = bitcast i8* %51 to i32*
store i32* %52, i32** %10
%53 = load i32*, i32** %7
%54 = getelementptr inbounds i32, i32* %53, i64 2
store volatile i32 57101, i32* %54
%55 = load i32*, i32** %7
%56 = getelementptr inbounds i32, i32* %55, i64 144
store volatile i32 0, i32* %56
%57 = load i32*, i32** %8
%58 = getelementptr inbounds i32, i32* %57, i64 0
%59 = load volatile i32, i32* %58
%60 = and i32 %59, -2
store volatile i32 %60, i32* %58
%61 = load i32*, i32** %8
%62 = getelementptr inbounds i32, i32* %61, i64 5
%63 = load volatile i32, i32* %62
%64 = and i32 %63, -2
store volatile i32 %64, i32* %62
%65 = load i8*, i8** %9
%66 = getelementptr i8, i8* %65, i64 0
%67 = bitcast i8* %66 to i32*
store i32* %67, i32** %5
%68 = load i8*, i8** %9
%69 = getelementptr i8, i8* %68, i64 4
%70 = bitcast i8* %69 to i32*
store i32* %70, i32** %6
%71 = load i32*, i32** %5
%72 = load volatile i32, i32* %71
%73 = and i32 %72, -5
store volatile i32 %73, i32* %71
%74 = load i32*, i32** %5
%75 = load volatile i32, i32* %74
%76 = or i32 %75, 4
store volatile i32 %76, i32* %74
%77 = load i32*, i32** %5
%78 = load volatile i32, i32* %77
%79 = and i32 %78, -2
store volatile i32 %79, i32* %77
%80 = load i32*, i32** %5
%81 = load volatile i32, i32* %80
%82 = or i32 %81, 1
store volatile i32 %82, i32* %80
%83 = call i32 @sleep(i32 1)
%84 = load i32*, i32** %5
%85 = load volatile i32, i32* %84
%86 = and i32 %85, -3
store volatile i32 %86, i32* %84
%87 = load i32*, i32** %6
store volatile i32 1048575, i32* %87
%88 = load i32*, i32** %5
%89 = load volatile i32, i32* %88
%90 = or i32 %89, 2
store volatile i32 %90, i32* %88
%91 = call i32 @sleep(i32 1)
store i32 0, i32* %3
br label %92
92: ; preds = %117, %16
%93 = load i32, i32* %3
%94 = icmp slt i32 %93, 1048576
br i1 %94, label %95, label %120
95: ; preds = %92
%96 = load i32*, i32** %10
%97 = load i32, i32* %3
%98 = mul nsw i32 2, %97
%99 = add nsw i32 %98, 0
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds i32, i32* %96, i64 %100
%102 = load volatile i32, i32* %101
%103 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
store i32 %102, i32* %103
%104 = load i32*, i32** %10
%105 = load i32, i32* %3
%106 = mul nsw i32 2, %105
%107 = add nsw i32 %106, 1
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds i32, i32* %104, i64 %108
%110 = load volatile i32, i32* %109
%111 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
store i32 %110, i32* %111
%112 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%113 = load i32, i32* %112
%114 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%115 = load i32, i32* %114
%116 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %113, i32 %115)
br label %117
117: ; preds = %95
%118 = load i32, i32* %3
%119 = add nsw i32 %118, 1
store i32 %119, i32* %3
br label %92
120: ; preds = %92
store i32 0, i32* %1
br label %121
121: ; preds = %120, %14
%122 = load i32, i32* %1
ret i32 %122
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@_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"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %76
6: ; preds = %0
%7 = load i32, i32* @_SC_PAGESIZE
%8 = tail call i32 @sysconf(i32 %7)
%9 = load i32, i32* @PROT_READ
%10 = load i32, i32* @PROT_WRITE
%11 = or i32 %10, %9
%12 = load i32, i32* @MAP_SHARED
%13 = tail call i8* @mmap(i32* null, i32 %8, i32 %11, i32 %12, i32 %2, i32 -134217728)
%14 = load i32, i32* @_SC_PAGESIZE
%15 = tail call i32 @sysconf(i32 %14)
%16 = load i32, i32* @PROT_READ
%17 = load i32, i32* @PROT_WRITE
%18 = or i32 %17, %16
%19 = load i32, i32* @MAP_SHARED
%20 = tail call i8* @mmap(i32* null, i32 %15, i32 %18, i32 %19, i32 %2, i32 -134184960)
%21 = bitcast i8* %20 to i32*
%22 = load i32, i32* @_SC_PAGESIZE
%23 = tail call i32 @sysconf(i32 %22)
%24 = load i32, i32* @PROT_READ
%25 = load i32, i32* @PROT_WRITE
%26 = or i32 %25, %24
%27 = load i32, i32* @MAP_SHARED
%28 = tail call i8* @mmap(i32* null, i32 %23, i32 %26, i32 %27, i32 %2, i32 1073741824)
%29 = load i32, i32* @_SC_PAGESIZE
%30 = tail call i32 @sysconf(i32 %29)
%31 = shl nsw i32 %30, 10
%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 %2, i32 503316480)
%37 = bitcast i8* %36 to i32*
%38 = getelementptr inbounds i8, i8* %13, i64 8
%39 = bitcast i8* %38 to i32*
store volatile i32 57101, i32* %39
%40 = getelementptr inbounds i8, i8* %13, i64 576
%41 = bitcast i8* %40 to i32*
store volatile i32 0, i32* %41
%42 = load volatile i32, i32* %21
%43 = and i32 %42, -2
store volatile i32 %43, i32* %21
%44 = getelementptr inbounds i8, i8* %20, i64 20
%45 = bitcast i8* %44 to i32*
%46 = load volatile i32, i32* %45
%47 = and i32 %46, -2
store volatile i32 %47, i32* %45
%48 = bitcast i8* %28 to i32*
%49 = getelementptr i8, i8* %28, i64 4
%50 = bitcast i8* %49 to i32*
%51 = load volatile i32, i32* %48
%52 = and i32 %51, -5
store volatile i32 %52, i32* %48
%53 = load volatile i32, i32* %48
%54 = or i32 %53, 4
store volatile i32 %54, i32* %48
%55 = load volatile i32, i32* %48
%56 = and i32 %55, -2
store volatile i32 %56, i32* %48
%57 = load volatile i32, i32* %48
%58 = or i32 %57, 1
store volatile i32 %58, i32* %48
%59 = tail call i32 @sleep(i32 1)
%60 = load volatile i32, i32* %48
%61 = and i32 %60, -3
store volatile i32 %61, i32* %48
store volatile i32 1048575, i32* %50
%62 = load volatile i32, i32* %48
%63 = or i32 %62, 2
store volatile i32 %63, i32* %48
%64 = tail call i32 @sleep(i32 1)
br label %65
65: ; preds = %6, %65
%66 = phi i64 [ 0, %6 ], [ %74, %65 ]
%67 = shl nuw nsw i64 %66, 1
%68 = getelementptr inbounds i32, i32* %37, i64 %67
%69 = load volatile i32, i32* %68
%70 = or i64 %67, 1
%71 = getelementptr inbounds i32, i32* %37, i64 %70
%72 = load volatile i32, i32* %71
%73 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %69, i32 %72)
%74 = add nuw nsw i64 %66, 1
%75 = icmp eq i64 %74, 1048576
br i1 %75, label %76, label %65
76: ; preds = %65, %4
%77 = phi i32 [ 1, %4 ], [ 0, %65 ]
ret i32 %77
}