#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;
  __u32 i, j;
  __u32 addr = 0;
  __u32 len = 0x01000000;
  __u32 ramplen = 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 [ramplen]]]\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) {
    ramplen = strtoul(argv[3], NULL, 16);
  }
  addr &= 0xfffffffc;
  len &= 0xfffffffc;
  ramplen &= 0xfffffffc;
  ramplen = ramplen > 8 ? ramplen : 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 ramp values\n");
  for (i = addr; i < addr + len; i += ramplen) {
    for (j = 0; j < ramplen && i + j < addr + len; j += 4) {
      __u32 k = j * 0x100 / ramplen;
      lmspace[(i + j) / 4] = k | k << 8 | k << 16 | k << 24;
      printf("writing 0x%08x to 0x%08x\n", k | k << 8 | k << 16 | k << 24,
             i + j);
    }
  }
  printf("Unmapping memory space\n");
  munmap(memspace, 0x01000000);
  close(memfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%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    14c4 <main+0x344>
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,-0x40(%rbp)
jmp    12b6 <main+0x136>
mov    $0x8,%eax
mov    %eax,-0x40(%rbp)
jmp    12b6 <main+0x136>
mov    -0x40(%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    0xd64(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1325 <main+0x1a5>
lea    0xd3d(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14c4 <main+0x344>
lea    0xd44(%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    0xd0f(%rip),%rdi
call   1090 <perror@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14c4 <main+0x344>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xd05(%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    1499 <main+0x319>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x28(%rbp),%ecx
mov    %al,-0x41(%rbp)
jge    13e9 <main+0x269>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    -0x20(%rbp),%ecx
add    -0x24(%rbp),%ecx
cmp    %ecx,%eax
setl   %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    13f9 <main+0x279>
jmp    1486 <main+0x306>
mov    -0x1c(%rbp),%eax
shl    $0x8,%eax
cltd
idivl  -0x28(%rbp)
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x3c(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x3c(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x3c(%rbp),%ecx
shl    $0x18,%ecx
or     %ecx,%eax
mov    %eax,-0x54(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x54(%rbp),%edx
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x3c(%rbp),%esi
mov    -0x3c(%rbp),%eax
shl    $0x8,%eax
or     %eax,%esi
mov    -0x3c(%rbp),%eax
shl    $0x10,%eax
or     %eax,%esi
mov    -0x3c(%rbp),%eax
shl    $0x18,%eax
or     %eax,%esi
mov    -0x18(%rbp),%edx
add    -0x1c(%rbp),%edx
lea    0xc48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x1c(%rbp)
jmp    13c4 <main+0x244>
jmp    148b <main+0x30b>
mov    -0x28(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    13ac <main+0x22c>
lea    0xc33(%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    $0x60,%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    0xf16(%rip),%rdi
call   1040 <puts@plt>
mov    (%rbx),%rsi
lea    0xe4e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%eax
jmp    1388 <main+0x1f8>
mov    %edi,%ebp
mov    $0x1000000,%r15d
xor    %r12d,%r12d
mov    $0x100,%r14d
cmp    $0x2,%edi
jl     1253 <main+0xc3>
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     1253 <main+0xc3>
mov    0x10(%rbx),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10b0 <strtoul@plt>
mov    %eax,%r15d
and    $0xfffffffc,%r15d
cmp    $0x3,%ebp
je     1253 <main+0xc3>
mov    0x18(%rbx),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10b0 <strtoul@plt>
mov    %eax,%r14d
and    $0xfffffffc,%r14d
mov    $0x8,%ebx
cmp    $0x9,%r14d
jl     1256 <main+0xc6>
mov    %r14d,%ebx
xor    %r13d,%r13d
cmp    $0x1000000,%r12d
cmovl  %r12d,%r13d
lea    (%r15,%r13,1),%eax
mov    $0x1000000,%r14d
sub    %r13d,%r14d
cmp    $0x1000000,%eax
cmovl  %r15d,%r14d
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
lea    0xdae(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1397 <main+0x207>
mov    %eax,%ebp
lea    0xde0(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d4c(%rip),%rax
mov    0x2d15(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d2a(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x1000000,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
test   %rax,%rax
je     13aa <main+0x21a>
mov    %rax,%r12
mov    %ebp,0x4(%rsp)
lea    0xdac(%rip),%rdi
call   1040 <puts@plt>
test   %r14d,%r14d
jle    1364 <main+0x1d4>
add    %r13d,%r14d
jmp    1308 <main+0x178>
nopl   0x0(%rax,%rax,1)
add    %ebx,%r13d
cmp    %r14d,%r13d
jge    1364 <main+0x1d4>
xor    %ebp,%ebp
xor    %r15d,%r15d
nopl   (%rax)
lea    (%r15,%r13,1),%ecx
cmp    %r14d,%ecx
jge    1300 <main+0x170>
mov    %ebp,%eax
xor    %edx,%edx
div    %ebx
mov    %eax,%edx
shl    $0x8,%edx
or     %eax,%edx
mov    %eax,%esi
shl    $0x10,%esi
shl    $0x18,%eax
or     %eax,%esi
or     %edx,%esi
lea    0x3(%rcx),%eax
test   %ecx,%ecx
cmovns %ecx,%eax
sar    $0x2,%eax
cltq
mov    %esi,(%r12,%rax,4)
lea    0xd1c(%rip),%rdi
mov    %ecx,%edx
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x4,%r15d
add    $0x400,%ebp
cmp    %ebx,%r15d
jl     1310 <main+0x180>
jmp    1300 <main+0x170>
lea    0xd3e(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
mov    $0x1000000,%esi
call   1080 <munmap@plt>
mov    0x4(%rsp),%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    0xc8b(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%eax
jmp    1388 <main+0x1f8>
lea    0xc97(%rip),%rdi
call   10a0 <perror@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    $0xffffffff,%eax
jmp    1388 <main+0x1f8>

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 = [34 x i8] c"Usage: %s [addr [len [ramplen]]]\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 = [21 x i8] c"Writing ramp values\0A\00"
@.str.8 = [26 x i8] c"writing 0x%08x to 0x%08x\0A\00"
@.str.9 = [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*
%14 = 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
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 4
br i1 %16, label %26, label %17
17: ; preds = %2
%18 = load i32, i32* %4
%19 = icmp sge i32 %18, 2
br i1 %19, label %20, label %32
20: ; preds = %17
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @strncmp(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%25 = icmp ne i32 %24, 0
br i1 %25, label %32, label %26
26: ; preds = %20, %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %30)
store i32 -1, i32* %3
br label %176
32: ; preds = %20, %17
%33 = load i32, i32* %4
%34 = icmp sge i32 %33, 2
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 @strtoul(i8* %38, i32* null, i32 16)
store i32 %39, i32* %9
br label %40
40: ; preds = %35, %32
%41 = load i32, i32* %4
%42 = icmp sge i32 %41, 3
br i1 %42, label %43, label %48
43: ; preds = %40
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32 @strtoul(i8* %46, i32* null, i32 16)
store i32 %47, i32* %10
br label %48
48: ; preds = %43, %40
%49 = load i32, i32* %4
%50 = icmp sge i32 %49, 4
br i1 %50, label %51, label %56
51: ; preds = %48
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 3
%54 = load i8*, i8** %53
%55 = call i32 @strtoul(i8* %54, i32* null, i32 16)
store i32 %55, i32* %11
br label %56
56: ; preds = %51, %48
%57 = load i32, i32* %9
%58 = and i32 %57, -4
store i32 %58, i32* %9
%59 = load i32, i32* %10
%60 = and i32 %59, -4
store i32 %60, i32* %10
%61 = load i32, i32* %11
%62 = and i32 %61, -4
store i32 %62, i32* %11
%63 = load i32, i32* %11
%64 = icmp sgt i32 %63, 8
br i1 %64, label %65, label %67
65: ; preds = %56
%66 = load i32, i32* %11
br label %68
67: ; preds = %56
br label %68
68: ; preds = %67, %65
%69 = phi i32 [ %66, %65 ], [ 8, %67 ]
store i32 %69, i32* %11
%70 = load i32, i32* %9
%71 = icmp sge i32 %70, 16777216
br i1 %71, label %72, label %73
72: ; preds = %68
store i32 0, i32* %9
br label %73
73: ; preds = %72, %68
%74 = load i32, i32* %9
%75 = load i32, i32* %10
%76 = add nsw i32 %74, %75
%77 = icmp sge i32 %76, 16777216
br i1 %77, label %78, label %81
78: ; preds = %73
%79 = load i32, i32* %9
%80 = sub nsw i32 16777216, %79
store i32 %80, i32* %10
br label %81
81: ; preds = %78, %73
%82 = load i32, i32* @O_RDWR
%83 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %82)
store i32 %83, i32* %6
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %81
%86 = 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 %176
87: ; preds = %81
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%89 = load i32, i32* @PROT_READ
%90 = load i32, i32* @PROT_WRITE
%91 = or i32 %89, %90
%92 = load i32, i32* @MAP_SHARED
%93 = load i32, i32* %6
%94 = call i8* @mmap(i32 0, i32 16777216, i32 %91, i32 %92, i32 %93, i32 0)
store i8* %94, i8** %12
%95 = icmp ne i8* %94, null
br i1 %95, label %100, label %96
96: ; preds = %87
%97 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%98 = load i32, i32* %6
%99 = call i32 @close(i32 %98)
store i32 -1, i32* %3
br label %176
100: ; preds = %87
%101 = load i8*, i8** %12
%102 = bitcast i8* %101 to i32*
store i32* %102, i32** %13
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
%104 = load i32, i32* %9
store i32 %104, i32* %7
br label %105
105: ; preds = %166, %100
%106 = load i32, i32* %7
%107 = load i32, i32* %9
%108 = load i32, i32* %10
%109 = add nsw i32 %107, %108
%110 = icmp slt i32 %106, %109
br i1 %110, label %111, label %170
111: ; preds = %105
store i32 0, i32* %8
br label %112
112: ; preds = %162, %111
%113 = load i32, i32* %8
%114 = load i32, i32* %11
%115 = icmp slt i32 %113, %114
br i1 %115, label %116, label %124
116: ; preds = %112
%117 = load i32, i32* %7
%118 = load i32, i32* %8
%119 = add nsw i32 %117, %118
%120 = load i32, i32* %9
%121 = load i32, i32* %10
%122 = add nsw i32 %120, %121
%123 = icmp slt i32 %119, %122
br label %124
124: ; preds = %116, %112
%125 = phi i1 [ false, %112 ], [ %123, %116 ]
br i1 %125, label %126, label %165
126: ; preds = %124
%127 = load i32, i32* %8
%128 = mul nsw i32 %127, 256
%129 = load i32, i32* %11
%130 = sdiv i32 %128, %129
store i32 %130, i32* %14
%131 = load i32, i32* %14
%132 = load i32, i32* %14
%133 = shl i32 %132, 8
%134 = or i32 %131, %133
%135 = load i32, i32* %14
%136 = shl i32 %135, 16
%137 = or i32 %134, %136
%138 = load i32, i32* %14
%139 = shl i32 %138, 24
%140 = or i32 %137, %139
%141 = load i32*, i32** %13
%142 = load i32, i32* %7
%143 = load i32, i32* %8
%144 = add nsw i32 %142, %143
%145 = sdiv i32 %144, 4
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds i32, i32* %141, i64 %146
store i32 %140, i32* %147
%148 = load i32, i32* %14
%149 = load i32, i32* %14
%150 = shl i32 %149, 8
%151 = or i32 %148, %150
%152 = load i32, i32* %14
%153 = shl i32 %152, 16
%154 = or i32 %151, %153
%155 = load i32, i32* %14
%156 = shl i32 %155, 24
%157 = or i32 %154, %156
%158 = load i32, i32* %7
%159 = load i32, i32* %8
%160 = add nsw i32 %158, %159
%161 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %157, i32 %160)
br label %162
162: ; preds = %126
%163 = load i32, i32* %8
%164 = add nsw i32 %163, 4
store i32 %164, i32* %8
br label %112
165: ; preds = %124
br label %166
166: ; preds = %165
%167 = load i32, i32* %11
%168 = load i32, i32* %7
%169 = add nsw i32 %168, %167
store i32 %169, i32* %7
br label %105
170: ; preds = %105
%171 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%172 = load i8*, i8** %12
%173 = call i32 @munmap(i8* %172, i32 16777216)
%174 = load i32, i32* %6
%175 = call i32 @close(i32 %174)
store i32 0, i32* %3
br label %176
176: ; preds = %170, %96, %85, %26
%177 = load i32, i32* %3
ret i32 %177
}

LLVM IR (-O2):
@.str = [7 x i8] c"--help\00"
@.str.2 = [34 x i8] c"Usage: %s [addr [len [ramplen]]]\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.8 = [26 x i8] c"writing 0x%08x to 0x%08x\0A\00"
@str = [21 x i8] c"Mapping memory space\00"
@str.10 = [20 x i8] c"Writing ramp values\00"
@str.11 = [23 x i8] c"Unmapping memory space\00"
@str.12 = [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.12, i64 0, i64 0))
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %95
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 %95
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 %95
62: ; preds = %51
%63 = bitcast i8* %57 to i32*
%64 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.10, i64 0, i64 0))
%65 = add nsw i32 %45, %41
%66 = icmp sgt i32 %45, 0
br i1 %66, label %67, label %91
67: ; preds = %62, %88
%68 = phi i32 [ %89, %88 ], [ %41, %62 ]
br label %69
69: ; preds = %67, %73
%70 = phi i32 [ %86, %73 ], [ 0, %67 ]
%71 = add nsw i32 %70, %68
%72 = icmp slt i32 %71, %65
br i1 %72, label %73, label %88
73: ; preds = %69
%74 = shl nsw i32 %70, 8
%75 = udiv i32 %74, %39
%76 = shl i32 %75, 8
%77 = or i32 %76, %75
%78 = shl i32 %75, 16
%79 = or i32 %77, %78
%80 = shl i32 %75, 24
%81 = or i32 %79, %80
%82 = sdiv i32 %71, 4
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i32, i32* %63, i64 %83
store i32 %81, i32* %84
%85 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %81, i32 %71)
%86 = add nuw nsw i32 %70, 4
%87 = icmp slt i32 %86, %39
br i1 %87, label %69, label %88
88: ; preds = %73, %69
%89 = add nsw i32 %68, %39
%90 = icmp slt i32 %89, %65
br i1 %90, label %67, label %91
91: ; preds = %88, %62
%92 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.11, i64 0, i64 0))
%93 = tail call i32 @munmap(i8* %57, i32 16777216)
%94 = tail call i32 @close(i32 %47)
br label %95
95: ; preds = %91, %59, %49, %11
%96 = phi i32 [ -1, %11 ], [ -1, %49 ], [ 0, %91 ], [ -1, %59 ]
ret i32 %96
}