#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 */
struct stat {
  int st_size;
};
typedef int __u32;

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
struct stat *calloc(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
scalar_t__ fstat(int, struct stat *);
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 read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int strtoul(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  int ifdr, ifd;
  __u32 addr = 0;
  __u32 len = 0x01000000;
  unsigned char *memspace;
  struct stat *dumpstat;
  if (argc < 2 || argc > 4) {
    printf("Loads tl880 memory\n");
    printf("Usage: %s mem_file [addr [len]]\n", argv[0]);
    return -1;
  }
  if (argc >= 3) {
    addr = strtoul(argv[2], NULL, 16);
  }
  if (argc == 4) {
    len = strtoul(argv[3], NULL, 16);
  }
  if ((ifdr = 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, ifdr, 0))) {
    perror("Failed to mmap card memory");
    close(ifdr);
    return -1;
  }
  if ((ifd = open(argv[1], O_RDONLY, 0)) < 0) {
    fprintf(stderr, "Failed to open input file %s: %s\n", argv[1],
            strerror(errno));
    munmap(memspace, 0x01000000);
    close(ifdr);
    return -1;
  }
  dumpstat = calloc(1, sizeof(struct stat));
  if (fstat(ifd, dumpstat)) {
    fprintf(stderr, "Couldn't stat %s: %s\n", argv[1], strerror(errno));
    munmap(memspace, 0x01000000);
    close(ifdr);
    close(ifd);
    return -1;
  }
  if (len > dumpstat->st_size) {
    len = dumpstat->st_size;
  }
  addr &= 0xfffffffc;
  len &= 0xfffffffc;
  if (addr >= 0x01000000) {
    addr = 0;
  }
  if (addr + len > 0x01000000) {
    len = 0x01000000 - addr;
  }
  printf("Loading 0x%x bytes of %s at address 0x%x\n", len, argv[1], addr);
  if (read(ifd, memspace + addr, len) != len) {
    perror("Failed to load memory dump\n");
    munmap(memspace, 0x01000000);
    close(ifdr);
    close(ifd);
    return -1;
  }
  close(ifd);
  printf("Unmapping memory space\n");
  munmap(memspace, 0x01000000);
  close(ifdr);
  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,-0x1c(%rbp)
movl   $0x1000000,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11f8 <main+0x38>
cmpl   $0x4,-0x8(%rbp)
jle    1227 <main+0x67>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1524 <main+0x364>
cmpl   $0x3,-0x8(%rbp)
jl     124a <main+0x8a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10c0 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    126d <main+0xad>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10c0 <strtoul@plt>
mov    %eax,-0x20(%rbp)
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    12a8 <main+0xe8>
lea    0xd9e(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1524 <main+0x364>
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edx
mov    0x2cea(%rip),%rax
or     (%rax),%edx
mov    0x2d19(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x1000000,%esi
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1313 <main+0x153>
lea    0xd70(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1524 <main+0x364>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2cae(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1397 <main+0x1d7>
mov    0x2c80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2c60(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xd15(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    $0x1000000,%esi
call   1090 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1524 <main+0x364>
mov    $0x1,%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   10e0 <fstat@plt>
cmp    $0x0,%rax
je     1426 <main+0x266>
mov    0x2bf9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    0x2bd9(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xcb0(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    $0x1000000,%esi
call   1090 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1524 <main+0x364>
mov    -0x20(%rbp),%eax
mov    -0x30(%rbp),%rcx
cmp    (%rcx),%eax
jle    143e <main+0x27e>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xfffffffc,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
and    $0xfffffffc,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x1000000,-0x1c(%rbp)
jl     1464 <main+0x2a4>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
cmp    $0x1000000,%eax
jle    1480 <main+0x2c0>
mov    $0x1000000,%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xc28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    -0x20(%rbp),%edx
call   1060 <read@plt>
cmp    -0x20(%rbp),%eax
je     14f1 <main+0x331>
lea    0xc25(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x28(%rbp),%rdi
mov    $0x1000000,%esi
call   1090 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1524 <main+0x364>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
lea    0xc03(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    $0x1000000,%esi
call   1090 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1050 <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
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    -0x5(%rbp),%eax
cmp    $0xfffffffc,%eax
ja     120d <main+0x3d>
lea    0xf13(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rsi
lea    0xdff(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1386 <main+0x1b6>
mov    $0x1000000,%r13d
xor    %r14d,%r14d
cmp    $0x3,%ebp
jb     124a <main+0x7a>
mov    0x10(%rbx),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10d0 <strtoul@plt>
mov    %eax,%r14d
and    $0xfffffffc,%r14d
cmp    $0x4,%ebp
jne    124a <main+0x7a>
mov    0x18(%rbx),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10d0 <strtoul@plt>
mov    %eax,%r13d
mov    0x2d87(%rip),%rax
mov    (%rax),%esi
lea    0xdd6(%rip),%rdi
xor    %eax,%eax
call   10b0 <open@plt>
test   %eax,%eax
js     1432 <main+0x262>
mov    %eax,%r12d
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d79(%rip),%rax
mov    0x2d2a(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d57(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x1000000,%esi
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
test   %rax,%rax
je     1443 <main+0x273>
mov    %rax,%r15
mov    %r13,0x10(%rsp)
mov    0x8(%rbx),%rdi
mov    0x2d0f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
xor    %eax,%eax
call   10b0 <open@plt>
test   %eax,%eax
js     1342 <main+0x172>
mov    %eax,%r13d
mov    $0x1,%edi
mov    $0x4,%esi
call   1080 <calloc@plt>
mov    %rax,%rbp
mov    %r13d,%edi
mov    %rax,%rsi
call   10f0 <fstat@plt>
test   %rax,%rax
je     139e <main+0x1ce>
mov    0x2cc0(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rbx
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xd62(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1090 <fprintf@plt>
mov    %r15,%rdi
mov    $0x1000000,%esi
call   10a0 <munmap@plt>
mov    %r12d,%edi
call   1060 <close@plt>
mov    %r13d,%edi
jmp    1381 <main+0x1b1>
mov    0x2c77(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rbx
mov    0x2c62(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xcf7(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1090 <fprintf@plt>
mov    %r15,%rdi
mov    $0x1000000,%esi
call   10a0 <munmap@plt>
mov    %r12d,%edi
call   1060 <close@plt>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12d,0xc(%rsp)
mov    0x0(%rbp),%eax
mov    0x10(%rsp),%rcx
cmp    %eax,%ecx
cmovg  %eax,%ecx
and    $0xfffffffc,%ecx
xor    %r12d,%r12d
cmp    $0x1000000,%r14d
cmovge %r12d,%r14d
lea    (%rcx,%r14,1),%eax
mov    $0x1000000,%ebp
sub    %r14d,%ebp
cmp    $0x1000001,%eax
cmovl  %ecx,%ebp
mov    0x8(%rbx),%rdx
lea    0xcb3(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
movslq %r14d,%rax
mov    %r15,%rsi
add    %rax,%rsi
mov    %r13d,%edi
mov    %ebp,%edx
call   1070 <read@plt>
cmp    %ebp,%eax
jne    1454 <main+0x284>
mov    %r13d,%edi
call   1060 <close@plt>
lea    0xcdc(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    $0x1000000,%esi
call   10a0 <munmap@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
jmp    138c <main+0x1bc>
lea    0xbe8(%rip),%rdi
call   10c0 <perror@plt>
jmp    1386 <main+0x1b6>
lea    0xbf6(%rip),%rdi
call   10c0 <perror@plt>
jmp    137e <main+0x1ae>
lea    0xc62(%rip),%rdi
call   10c0 <perror@plt>
mov    %r15,%rdi
mov    $0x1000000,%esi
call   10a0 <munmap@plt>
mov    0xc(%rsp),%edi
jmp    1338 <main+0x168>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [20 x i8] c"Loads tl880 memory\0A\00"
@.str.1 = [33 x i8] c"Usage: %s mem_file [addr [len]]\0A\00"
@.str.2 = [16 x i8] c"/dev/tl880/mem0\00"
@O_RDWR = global i32 0
@.str.3 = [31 x i8] c"Unable to open /dev/tl880/mem0\00"
@.str.4 = [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.5 = [27 x i8] c"Failed to mmap card memory\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.6 = [34 x i8] c"Failed to open input file %s: %s\0A\00"
@errno = global i32 0
@.str.7 = [22 x i8] c"Couldn't stat %s: %s\0A\00"
@.str.8 = [42 x i8] c"Loading 0x%x bytes of %s at address 0x%x\0A\00"
@.str.9 = [28 x i8] c"Failed to load memory dump\0A\00"
@.str.10 = [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 i8*
%11 = alloca %struct.stat*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 16777216, i32* %9
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 4
br i1 %16, label %17, label %23
17: ; preds = %14, %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %21)
store i32 -1, i32* %3
br label %155
23: ; preds = %14
%24 = load i32, i32* %4
%25 = icmp sge i32 %24, 3
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @strtoul(i8* %29, i32* null, i32 16)
store i32 %30, i32* %8
br label %31
31: ; preds = %26, %23
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, 4
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 3
%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* @O_RDWR
%41 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %40)
store i32 %41, i32* %6
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %155
45: ; preds = %39
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%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* %6
%52 = call i8* @mmap(i32 0, i32 16777216, i32 %49, i32 %50, i32 %51, i32 0)
store i8* %52, i8** %10
%53 = icmp ne i8* %52, null
br i1 %53, label %58, label %54
54: ; preds = %45
%55 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%56 = load i32, i32* %6
%57 = call i32 @close(i32 %56)
store i32 -1, i32* %3
br label %155
58: ; preds = %45
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 1
%61 = load i8*, i8** %60
%62 = load i32, i32* @O_RDONLY
%63 = call i32 (i8*, i32, ...) @open(i8* %61, i32 %62, i32 0)
store i32 %63, i32* %7
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %77
65: ; preds = %58
%66 = load i32, i32* @stderr
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 1
%69 = load i8*, i8** %68
%70 = load i32, i32* @errno
%71 = call i8* @strerror(i32 %70)
%72 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %69, i8* %71)
%73 = load i8*, i8** %10
%74 = call i32 @munmap(i8* %73, i32 16777216)
%75 = load i32, i32* %6
%76 = call i32 @close(i32 %75)
store i32 -1, i32* %3
br label %155
77: ; preds = %58
%78 = call %struct.stat* @calloc(i32 1, i32 4)
store %struct.stat* %78, %struct.stat** %11
%79 = load i32, i32* %7
%80 = load %struct.stat*, %struct.stat** %11
%81 = call i64 @fstat(i32 %79, %struct.stat* %80)
%82 = icmp ne i64 %81, 0
br i1 %82, label %83, label %97
83: ; preds = %77
%84 = load i32, i32* @stderr
%85 = load i8**, i8*** %5
%86 = getelementptr inbounds i8*, i8** %85, i64 1
%87 = load i8*, i8** %86
%88 = load i32, i32* @errno
%89 = call i8* @strerror(i32 %88)
%90 = call i32 @fprintf(i32 %84, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %87, i8* %89)
%91 = load i8*, i8** %10
%92 = call i32 @munmap(i8* %91, i32 16777216)
%93 = load i32, i32* %6
%94 = call i32 @close(i32 %93)
%95 = load i32, i32* %7
%96 = call i32 @close(i32 %95)
store i32 -1, i32* %3
br label %155
97: ; preds = %77
%98 = load i32, i32* %9
%99 = load %struct.stat*, %struct.stat** %11
%100 = getelementptr inbounds %struct.stat, %struct.stat* %99, i32 0, i32 0
%101 = load i32, i32* %100
%102 = icmp sgt i32 %98, %101
br i1 %102, label %103, label %107
103: ; preds = %97
%104 = load %struct.stat*, %struct.stat** %11
%105 = getelementptr inbounds %struct.stat, %struct.stat* %104, i32 0, i32 0
%106 = load i32, i32* %105
store i32 %106, i32* %9
br label %107
107: ; preds = %103, %97
%108 = load i32, i32* %8
%109 = and i32 %108, -4
store i32 %109, i32* %8
%110 = load i32, i32* %9
%111 = and i32 %110, -4
store i32 %111, i32* %9
%112 = load i32, i32* %8
%113 = icmp sge i32 %112, 16777216
br i1 %113, label %114, label %115
114: ; preds = %107
store i32 0, i32* %8
br label %115
115: ; preds = %114, %107
%116 = load i32, i32* %8
%117 = load i32, i32* %9
%118 = add nsw i32 %116, %117
%119 = icmp sgt i32 %118, 16777216
br i1 %119, label %120, label %123
120: ; preds = %115
%121 = load i32, i32* %8
%122 = sub nsw i32 16777216, %121
store i32 %122, i32* %9
br label %123
123: ; preds = %120, %115
%124 = load i32, i32* %9
%125 = load i8**, i8*** %5
%126 = getelementptr inbounds i8*, i8** %125, i64 1
%127 = load i8*, i8** %126
%128 = load i32, i32* %8
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0), i32 %124, i8* %127, i32 %128)
%130 = load i32, i32* %7
%131 = load i8*, i8** %10
%132 = load i32, i32* %8
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds i8, i8* %131, i64 %133
%135 = load i32, i32* %9
%136 = call i32 @read(i32 %130, i8* %134, i32 %135)
%137 = load i32, i32* %9
%138 = icmp ne i32 %136, %137
br i1 %138, label %139, label %147
139: ; preds = %123
%140 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0))
%141 = load i8*, i8** %10
%142 = call i32 @munmap(i8* %141, i32 16777216)
%143 = load i32, i32* %6
%144 = call i32 @close(i32 %143)
%145 = load i32, i32* %7
%146 = call i32 @close(i32 %145)
store i32 -1, i32* %3
br label %155
147: ; preds = %123
%148 = load i32, i32* %7
%149 = call i32 @close(i32 %148)
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
%151 = load i8*, i8** %10
%152 = call i32 @munmap(i8* %151, i32 16777216)
%153 = load i32, i32* %6
%154 = call i32 @close(i32 %153)
store i32 0, i32* %3
br label %155
155: ; preds = %147, %139, %83, %65, %54, %43, %17
%156 = load i32, i32* %3
ret i32 %156
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str.1 = [33 x i8] c"Usage: %s mem_file [addr [len]]\0A\00"
@.str.2 = [16 x i8] c"/dev/tl880/mem0\00"
@O_RDWR = global i32 0
@.str.3 = [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.5 = [27 x i8] c"Failed to mmap card memory\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.6 = [34 x i8] c"Failed to open input file %s: %s\0A\00"
@errno = global i32 0
@.str.7 = [22 x i8] c"Couldn't stat %s: %s\0A\00"
@.str.8 = [42 x i8] c"Loading 0x%x bytes of %s at address 0x%x\0A\00"
@.str.9 = [28 x i8] c"Failed to load memory dump\0A\00"
@str = [21 x i8] c"Mapping memory space\00"
@str.11 = [23 x i8] c"Unmapping memory space\00"
@str.12 = [19 x i8] c"Loads tl880 memory\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = add i32 %0, -5
%4 = icmp ult i32 %3, -3
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.12, i64 0, i64 0))
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %95
9: ; preds = %2
%10 = icmp ugt i32 %0, 2
br i1 %10, label %11, label %21
11: ; preds = %9
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @strtoul(i8* nocapture %13, i32* null, i32 16)
%15 = and i32 %14, -4
%16 = icmp eq i32 %0, 4
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = getelementptr inbounds i8*, i8** %1, i64 3
%19 = load i8*, i8** %18
%20 = tail call i32 @strtoul(i8* nocapture %19, i32* null, i32 16)
br label %21
21: ; preds = %9, %17, %11
%22 = phi i32 [ %15, %17 ], [ %15, %11 ], [ 0, %9 ]
%23 = phi i32 [ %20, %17 ], [ 16777216, %11 ], [ 16777216, %9 ]
%24 = load i32, i32* @O_RDWR
%25 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %95
29: ; preds = %21
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%31 = load i32, i32* @PROT_READ
%32 = load i32, i32* @PROT_WRITE
%33 = or i32 %32, %31
%34 = load i32, i32* @MAP_SHARED
%35 = tail call i8* @mmap(i32 0, i32 16777216, i32 %33, i32 %34, i32 %25, i32 0)
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %40
37: ; preds = %29
%38 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%39 = tail call i32 @close(i32 %25)
br label %95
40: ; preds = %29
%41 = getelementptr inbounds i8*, i8** %1, i64 1
%42 = load i8*, i8** %41
%43 = load i32, i32* @O_RDONLY
%44 = tail call i32 (i8*, i32, ...) @open(i8* %42, i32 %43, i32 0)
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %54
46: ; preds = %40
%47 = load i32, i32* @stderr
%48 = load i8*, i8** %41
%49 = load i32, i32* @errno
%50 = tail call i8* @strerror(i32 %49)
%51 = tail call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %48, i8* %50)
%52 = tail call i32 @munmap(i8* %35, i32 16777216)
%53 = tail call i32 @close(i32 %25)
br label %95
54: ; preds = %40
%55 = tail call %struct.stat* @calloc(i32 1, i32 4)
%56 = tail call i64 @fstat(i32 %44, %struct.stat* %55)
%57 = icmp eq i64 %56, 0
br i1 %57, label %67, label %58
58: ; preds = %54
%59 = load i32, i32* @stderr
%60 = load i8*, i8** %41
%61 = load i32, i32* @errno
%62 = tail call i8* @strerror(i32 %61)
%63 = tail call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %60, i8* %62)
%64 = tail call i32 @munmap(i8* %35, i32 16777216)
%65 = tail call i32 @close(i32 %25)
%66 = tail call i32 @close(i32 %44)
br label %95
67: ; preds = %54
%68 = getelementptr inbounds %struct.stat, %struct.stat* %55, i64 0, i32 0
%69 = load i32, i32* %68
%70 = icmp sgt i32 %23, %69
%71 = select i1 %70, i32 %69, i32 %23
%72 = and i32 %71, -4
%73 = icmp sgt i32 %22, 16777215
%74 = select i1 %73, i32 0, i32 %22
%75 = add nsw i32 %72, %74
%76 = icmp sgt i32 %75, 16777216
%77 = sub nsw i32 16777216, %74
%78 = select i1 %76, i32 %77, i32 %72
%79 = load i8*, i8** %41
%80 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0), i32 %78, i8* %79, i32 %74)
%81 = sext i32 %74 to i64
%82 = getelementptr inbounds i8, i8* %35, i64 %81
%83 = tail call i32 @read(i32 %44, i8* %82, i32 %78)
%84 = icmp eq i32 %83, %78
br i1 %84, label %90, label %85
85: ; preds = %67
%86 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0))
%87 = tail call i32 @munmap(i8* %35, i32 16777216)
%88 = tail call i32 @close(i32 %25)
%89 = tail call i32 @close(i32 %44)
br label %95
90: ; preds = %67
%91 = tail call i32 @close(i32 %44)
%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* %35, i32 16777216)
%94 = tail call i32 @close(i32 %25)
br label %95
95: ; preds = %90, %85, %58, %46, %37, %27, %5
%96 = phi i32 [ -1, %5 ], [ -1, %27 ], [ -1, %46 ], [ -1, %58 ], [ -1, %85 ], [ 0, %90 ], [ -1, %37 ]
ret i32 %96
}