#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 __u32;

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ close(int);
unsigned char *mmap(int /*<<< orphan*/, int, int, int /*<<< orphan*/, int,
                    int /*<<< orphan*/);
int /*<<< orphan*/ munmap(unsigned char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strncmp(char *, char *, int);
int strtoul(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  int memfd, i, j;
  __u32 addr = 0;
  __u32 len = 0x01000000;
  __u32 width = 0x100;
  unsigned char *memspace;
  __u32 *lmspace;
  if (argc > 4 || (argc >= 2 && !strncmp(argv[1], "--help", 6))) {
    printf("Writes alternating values to TL880 RAM\n");
    printf("Usage: %s [addr [len] [width]]\n", argv[0]);
    return -1;
  }
  if (argc >= 2) {
    addr = strtoul(argv[1], NULL, 16);
  }
  if (argc >= 3) {
    len = strtoul(argv[2], NULL, 16);
  }
  if (argc >= 4) {
    width = strtoul(argv[3], NULL, 16);
  }
  addr &= 0xfffffffc;
  len &= 0xfffffffc;
  width &= 0xfffffffc;
  width = width > 8 ? width : 8;
  if (addr >= 0x01000000) {
    addr = 0;
  }
  if (addr + len >= 0x01000000) {
    len = 0x01000000 - addr;
  }
  if ((memfd = open("/dev/tl880/mem0", O_RDWR)) < 0) {
    perror("Unable to open /dev/tl880/mem0");
    return -1;
  }
  printf("Mapping memory space\n");
  if (!(memspace = mmap(0, 0x01000000, PROT_READ | PROT_WRITE, MAP_SHARED,
                        memfd, 0))) {
    perror("Failed to mmap region 1 (mem)");
    close(memfd);
    return -1;
  }
  lmspace = (__u32 *)memspace;
  printf("Writing stripe values\n");
  for (i = addr; i < addr + len; i += width) {
    for (j = 0; j < width / 2; j += 4) {
      lmspace[(i + j) / 4] = 0xffffffff;
    }
    for (j = width / 2; j < width; j += 4) {
      lmspace[(i + j) / 4] = 0x00000000;
    }
  }
  printf("Unmapping memory space\n");
  munmap(memspace, 0x01000000);
  close(memfd);
  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)
movl   $0x0,-0x20(%rbp)
movl   $0x1000000,-0x24(%rbp)
movl   $0x100,-0x28(%rbp)
cmpl   $0x4,-0x8(%rbp)
jg     11e1 <main+0x61>
cmpl   $0x2,-0x8(%rbp)
jl     1210 <main+0x90>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe32(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1210 <main+0x90>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14a2 <main+0x322>
cmpl   $0x2,-0x8(%rbp)
jl     1233 <main+0xb3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10a0 <strtoul@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     1256 <main+0xd6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10a0 <strtoul@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x4,-0x8(%rbp)
jl     1279 <main+0xf9>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10a0 <strtoul@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
and    $0xfffffffc,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
and    $0xfffffffc,%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
and    $0xfffffffc,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x8,-0x28(%rbp)
jle    12a9 <main+0x129>
mov    -0x28(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    12b6 <main+0x136>
mov    $0x8,%eax
mov    %eax,-0x3c(%rbp)
jmp    12b6 <main+0x136>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x1000000,-0x20(%rbp)
jl     12d0 <main+0x150>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    -0x24(%rbp),%eax
cmp    $0x1000000,%eax
jl     12ec <main+0x16c>
mov    $0x1000000,%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2ce5(%rip),%rax
mov    (%rax),%esi
lea    0xd62(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1325 <main+0x1a5>
lea    0xd3b(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14a2 <main+0x322>
lea    0xd42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2cbe(%rip),%rax
mov    (%rax),%edx
mov    0x2c85(%rip),%rax
or     (%rax),%edx
mov    0x2c9c(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x1000000,%esi
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1390 <main+0x210>
lea    0xd0d(%rip),%rdi
call   1090 <perror@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14a2 <main+0x322>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xd03(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x20(%rbp),%ecx
add    -0x24(%rbp),%ecx
cmp    %ecx,%eax
jge    1477 <main+0x2f7>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
cmp    %ecx,%eax
jge    1416 <main+0x296>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x1c(%rbp)
jmp    13c4 <main+0x244>
mov    -0x28(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1464 <main+0x2e4>
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
movslq %ecx,%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x1c(%rbp)
jmp    1424 <main+0x2a4>
jmp    1469 <main+0x2e9>
mov    -0x28(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    13ac <main+0x22c>
lea    0xc3b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    $0x1000000,%esi
call   1070 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
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    %rsi,%rbx
cmp    $0x4,%edi
jle    11ca <main+0x3a>
lea    0xefc(%rip),%rdi
call   1040 <puts@plt>
mov    (%rbx),%rsi
lea    0xe4e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%eax
jmp    1385 <main+0x1f5>
mov    %edi,%ebp
mov    $0x1000000,%r15d
xor    %r12d,%r12d
mov    $0x100,%r14d
cmp    $0x2,%edi
jl     1254 <main+0xc4>
mov    0x8(%rbx),%rdi
lea    0xe15(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11a3 <main+0x13>
mov    0x8(%rbx),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10b0 <strtoul@plt>
mov    %eax,%r12d
and    $0xfffffffc,%r12d
cmp    $0x3,%ebp
jb     1254 <main+0xc4>
mov    0x10(%rbx),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10b0 <strtoul@plt>
mov    %eax,%r15d
and    $0xfffffffc,%r15d
cmp    $0x3,%ebp
je     1254 <main+0xc4>
mov    0x18(%rbx),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10b0 <strtoul@plt>
mov    %eax,%r14d
and    $0xfffffffc,%r14d
mov    $0x8,%r13d
cmp    $0x9,%r14d
jl     1257 <main+0xc7>
mov    %r14d,%r13d
xor    %ebp,%ebp
cmp    $0x1000000,%r12d
cmovl  %r12d,%ebp
lea    (%r15,%rbp,1),%eax
mov    $0x1000000,%r12d
sub    %ebp,%r12d
cmp    $0x1000000,%eax
cmovl  %r15d,%r12d
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
lea    0xdac(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1394 <main+0x204>
mov    %eax,%r14d
lea    0xdc3(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d4b(%rip),%rax
mov    0x2d14(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d29(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x1000000,%esi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
test   %rax,%rax
je     13a7 <main+0x217>
mov    %rax,%rbx
lea    0xd93(%rip),%rdi
call   1040 <puts@plt>
test   %r12d,%r12d
jle    1362 <main+0x1d2>
add    %ebp,%r12d
mov    %r13d,%eax
shr    %eax
jmp    1308 <main+0x178>
nopw   0x0(%rax,%rax,1)
add    %r13d,%ebp
cmp    %r12d,%ebp
jge    1362 <main+0x1d2>
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edx
add    %ecx,%edx
lea    0x3(%rbp,%rcx,1),%esi
cmovns %edx,%esi
sar    $0x2,%esi
movslq %esi,%rdx
movl   $0xffffffff,(%rbx,%rdx,4)
add    $0x4,%ecx
cmp    %eax,%ecx
jb     1310 <main+0x180>
mov    %eax,%ecx
cmp    %r13d,%eax
jae    1300 <main+0x170>
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edx
add    %ecx,%edx
lea    0x3(%rbp,%rcx,1),%esi
cmovns %edx,%esi
sar    $0x2,%esi
movslq %esi,%rdx
movl   $0x0,(%rbx,%rdx,4)
add    $0x4,%ecx
cmp    %r13d,%ecx
jl     1340 <main+0x1b0>
jmp    1300 <main+0x170>
lea    0xd26(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0x1000000,%esi
call   1080 <munmap@plt>
mov    %r14d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc8c(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%eax
jmp    1385 <main+0x1f5>
lea    0xc98(%rip),%rdi
call   10a0 <perror@plt>
mov    %r14d,%edi
call   1070 <close@plt>
mov    $0xffffffff,%eax
jmp    1385 <main+0x1f5>

LLVM IR (-O0):
@.str = [7 x i8] c"--help\00"
@.str.1 = [40 x i8] c"Writes alternating values to TL880 RAM\0A\00"
@.str.2 = [32 x i8] c"Usage: %s [addr [len] [width]]\0A\00"
@.str.3 = [16 x i8] c"/dev/tl880/mem0\00"
@O_RDWR = global i32 0
@.str.4 = [31 x i8] c"Unable to open /dev/tl880/mem0\00"
@.str.5 = [22 x i8] c"Mapping memory space\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.6 = [30 x i8] c"Failed to mmap region 1 (mem)\00"
@.str.7 = [23 x i8] c"Writing stripe values\0A\00"
@.str.8 = [24 x i8] c"Unmapping memory space\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
store i32 16777216, i32* %10
store i32 256, i32* %11
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 4
br i1 %15, label %25, label %16
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp sge i32 %17, 2
br i1 %18, label %19, label %31
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @strncmp(i8* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%24 = icmp ne i32 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %19, %2
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %29)
store i32 -1, i32* %3
br label %156
31: ; preds = %19, %16
%32 = load i32, i32* %4
%33 = icmp sge i32 %32, 2
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @strtoul(i8* %37, i32* null, i32 16)
store i32 %38, i32* %9
br label %39
39: ; preds = %34, %31
%40 = load i32, i32* %4
%41 = icmp sge i32 %40, 3
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32 @strtoul(i8* %45, i32* null, i32 16)
store i32 %46, i32* %10
br label %47
47: ; preds = %42, %39
%48 = load i32, i32* %4
%49 = icmp sge i32 %48, 4
br i1 %49, label %50, label %55
50: ; preds = %47
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 3
%53 = load i8*, i8** %52
%54 = call i32 @strtoul(i8* %53, i32* null, i32 16)
store i32 %54, i32* %11
br label %55
55: ; preds = %50, %47
%56 = load i32, i32* %9
%57 = and i32 %56, -4
store i32 %57, i32* %9
%58 = load i32, i32* %10
%59 = and i32 %58, -4
store i32 %59, i32* %10
%60 = load i32, i32* %11
%61 = and i32 %60, -4
store i32 %61, i32* %11
%62 = load i32, i32* %11
%63 = icmp sgt i32 %62, 8
br i1 %63, label %64, label %66
64: ; preds = %55
%65 = load i32, i32* %11
br label %67
66: ; preds = %55
br label %67
67: ; preds = %66, %64
%68 = phi i32 [ %65, %64 ], [ 8, %66 ]
store i32 %68, i32* %11
%69 = load i32, i32* %9
%70 = icmp sge i32 %69, 16777216
br i1 %70, label %71, label %72
71: ; preds = %67
store i32 0, i32* %9
br label %72
72: ; preds = %71, %67
%73 = load i32, i32* %9
%74 = load i32, i32* %10
%75 = add nsw i32 %73, %74
%76 = icmp sge i32 %75, 16777216
br i1 %76, label %77, label %80
77: ; preds = %72
%78 = load i32, i32* %9
%79 = sub nsw i32 16777216, %78
store i32 %79, i32* %10
br label %80
80: ; preds = %77, %72
%81 = load i32, i32* @O_RDWR
%82 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %81)
store i32 %82, i32* %6
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %80
%85 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %156
86: ; preds = %80
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%88 = load i32, i32* @PROT_READ
%89 = load i32, i32* @PROT_WRITE
%90 = or i32 %88, %89
%91 = load i32, i32* @MAP_SHARED
%92 = load i32, i32* %6
%93 = call i8* @mmap(i32 0, i32 16777216, i32 %90, i32 %91, i32 %92, i32 0)
store i8* %93, i8** %12
%94 = icmp ne i8* %93, null
br i1 %94, label %99, label %95
95: ; preds = %86
%96 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%97 = load i32, i32* %6
%98 = call i32 @close(i32 %97)
store i32 -1, i32* %3
br label %156
99: ; preds = %86
%100 = load i8*, i8** %12
%101 = bitcast i8* %100 to i32*
store i32* %101, i32** %13
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%103 = load i32, i32* %9
store i32 %103, i32* %7
br label %104
104: ; preds = %146, %99
%105 = load i32, i32* %7
%106 = load i32, i32* %9
%107 = load i32, i32* %10
%108 = add nsw i32 %106, %107
%109 = icmp slt i32 %105, %108
br i1 %109, label %110, label %150
110: ; preds = %104
store i32 0, i32* %8
br label %111
111: ; preds = %124, %110
%112 = load i32, i32* %8
%113 = load i32, i32* %11
%114 = sdiv i32 %113, 2
%115 = icmp slt i32 %112, %114
br i1 %115, label %116, label %127
116: ; preds = %111
%117 = load i32*, i32** %13
%118 = load i32, i32* %7
%119 = load i32, i32* %8
%120 = add nsw i32 %118, %119
%121 = sdiv i32 %120, 4
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds i32, i32* %117, i64 %122
store i32 -1, i32* %123
br label %124
124: ; preds = %116
%125 = load i32, i32* %8
%126 = add nsw i32 %125, 4
store i32 %126, i32* %8
br label %111
127: ; preds = %111
%128 = load i32, i32* %11
%129 = sdiv i32 %128, 2
store i32 %129, i32* %8
br label %130
130: ; preds = %142, %127
%131 = load i32, i32* %8
%132 = load i32, i32* %11
%133 = icmp slt i32 %131, %132
br i1 %133, label %134, label %145
134: ; preds = %130
%135 = load i32*, i32** %13
%136 = load i32, i32* %7
%137 = load i32, i32* %8
%138 = add nsw i32 %136, %137
%139 = sdiv i32 %138, 4
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds i32, i32* %135, i64 %140
store i32 0, i32* %141
br label %142
142: ; preds = %134
%143 = load i32, i32* %8
%144 = add nsw i32 %143, 4
store i32 %144, i32* %8
br label %130
145: ; preds = %130
br label %146
146: ; preds = %145
%147 = load i32, i32* %11
%148 = load i32, i32* %7
%149 = add nsw i32 %148, %147
store i32 %149, i32* %7
br label %104
150: ; preds = %104
%151 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%152 = load i8*, i8** %12
%153 = call i32 @munmap(i8* %152, i32 16777216)
%154 = load i32, i32* %6
%155 = call i32 @close(i32 %154)
store i32 0, i32* %3
br label %156
156: ; preds = %150, %95, %84, %25
%157 = load i32, i32* %3
ret i32 %157
}

LLVM IR (-O2):
@.str = [7 x i8] c"--help\00"
@.str.2 = [32 x i8] c"Usage: %s [addr [len] [width]]\0A\00"
@.str.3 = [16 x i8] c"/dev/tl880/mem0\00"
@O_RDWR = global i32 0
@.str.4 = [31 x i8] c"Unable to open /dev/tl880/mem0\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.6 = [30 x i8] c"Failed to mmap region 1 (mem)\00"
@str = [21 x i8] c"Mapping memory space\00"
@str.9 = [22 x i8] c"Writing stripe values\00"
@str.10 = [23 x i8] c"Unmapping memory space\00"
@str.11 = [39 x i8] c"Writes alternating values to TL880 RAM\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 4
br i1 %3, label %11, label %4
4: ; preds = %2
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %32
6: ; preds = %4
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strncmp(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %6, %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.11, i64 0, i64 0))
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %96
15: ; preds = %6
%16 = load i8*, i8** %7
%17 = tail call i32 @strtoul(i8* nocapture %16, i32* null, i32 16)
%18 = and i32 %17, -4
%19 = icmp ugt i32 %0, 2
br i1 %19, label %20, label %32
20: ; preds = %15
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32 @strtoul(i8* nocapture %22, i32* null, i32 16)
%24 = and i32 %23, -4
%25 = icmp eq i32 %0, 3
br i1 %25, label %32, label %26
26: ; preds = %20
%27 = getelementptr inbounds i8*, i8** %1, i64 3
%28 = load i8*, i8** %27
%29 = tail call i32 @strtoul(i8* nocapture %28, i32* null, i32 16)
%30 = and i32 %29, -4
%31 = icmp sgt i32 %30, 8
br i1 %31, label %32, label %36
32: ; preds = %4, %15, %20, %26
%33 = phi i32 [ %30, %26 ], [ 256, %20 ], [ 256, %15 ], [ 256, %4 ]
%34 = phi i32 [ %18, %26 ], [ %18, %20 ], [ %18, %15 ], [ 0, %4 ]
%35 = phi i32 [ %24, %26 ], [ %24, %20 ], [ 16777216, %15 ], [ 16777216, %4 ]
br label %36
36: ; preds = %26, %32
%37 = phi i32 [ %34, %32 ], [ %18, %26 ]
%38 = phi i32 [ %35, %32 ], [ %24, %26 ]
%39 = phi i32 [ %33, %32 ], [ 8, %26 ]
%40 = icmp sgt i32 %37, 16777215
%41 = select i1 %40, i32 0, i32 %37
%42 = add nsw i32 %41, %38
%43 = icmp sgt i32 %42, 16777215
%44 = sub nsw i32 16777216, %41
%45 = select i1 %43, i32 %44, i32 %38
%46 = load i32, i32* @O_RDWR
%47 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %46)
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %36
%50 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
br label %96
51: ; preds = %36
%52 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%53 = load i32, i32* @PROT_READ
%54 = load i32, i32* @PROT_WRITE
%55 = or i32 %54, %53
%56 = load i32, i32* @MAP_SHARED
%57 = tail call i8* @mmap(i32 0, i32 16777216, i32 %55, i32 %56, i32 %47, i32 0)
%58 = icmp eq i8* %57, null
br i1 %58, label %59, label %62
59: ; preds = %51
%60 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%61 = tail call i32 @close(i32 %47)
br label %96
62: ; preds = %51
%63 = bitcast i8* %57 to i32*
%64 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.9, i64 0, i64 0))
%65 = add nsw i32 %45, %41
%66 = icmp sgt i32 %45, 0
br i1 %66, label %67, label %92
67: ; preds = %62
%68 = lshr exact i32 %39, 1
%69 = icmp ult i32 %68, %39
br label %70
70: ; preds = %67, %89
%71 = phi i32 [ %41, %67 ], [ %90, %89 ]
br label %73
72: ; preds = %73
br i1 %69, label %81, label %89
73: ; preds = %70, %73
%74 = phi i32 [ %79, %73 ], [ 0, %70 ]
%75 = add nsw i32 %74, %71
%76 = sdiv i32 %75, 4
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i32, i32* %63, i64 %77
store i32 -1, i32* %78
%79 = add nuw nsw i32 %74, 4
%80 = icmp ult i32 %79, %68
br i1 %80, label %73, label %72
81: ; preds = %72, %81
%82 = phi i32 [ %87, %81 ], [ %68, %72 ]
%83 = add nsw i32 %82, %71
%84 = sdiv i32 %83, 4
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i32, i32* %63, i64 %85
store i32 0, i32* %86
%87 = add nuw nsw i32 %82, 4
%88 = icmp slt i32 %87, %39
br i1 %88, label %81, label %89
89: ; preds = %81, %72
%90 = add nsw i32 %71, %39
%91 = icmp slt i32 %90, %65
br i1 %91, label %70, label %92
92: ; preds = %89, %62
%93 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.10, i64 0, i64 0))
%94 = tail call i32 @munmap(i8* %57, i32 16777216)
%95 = tail call i32 @close(i32 %47)
br label %96
96: ; preds = %92, %59, %49, %11
%97 = phi i32 [ -1, %11 ], [ -1, %49 ], [ 0, %92 ], [ -1, %59 ]
ret i32 %97
}