#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 O_CREAT;
int /*<<< orphan*/ O_RDWR;
int O_TRUNC;
int O_WRONLY;
int PROT_READ;
int PROT_WRITE;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
unsigned char *mmap(int /*<<< orphan*/, int, int, int /*<<< orphan*/, int,
                    int /*<<< orphan*/);
int /*<<< orphan*/ munmap(unsigned char *, int);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int strtoul(char *, int /*<<< orphan*/ *, int);
int write(int, unsigned char *, int);
int main(int argc, char *argv[]) {
  int ifdr, ofd;
  __u32 addr = 0;
  __u32 len = 0x01000000;
  unsigned char *memspace;
  if (argc < 2 || argc > 4) {
    printf("Dumps 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;
  }
  addr &= 0xfffffffc;
  len &= 0xfffffffc;
  if (addr >= 0x01000000) {
    addr = 0;
  }
  if (addr + len > 0x01000000) {
    len = 0x01000000 - addr;
  }
  printf("Writing 0x%x bytes starting at offset 0x%x to %s\n", len, addr,
         argv[1]);
  if ((ofd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC,
                  S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) {
    fprintf(stderr, "Failed to open output file %s: %s\n", argv[1],
            strerror(errno));
    munmap(memspace, 0x01000000);
    close(ifdr);
    return -1;
  }
  if (write(ofd, memspace + addr, len) != len) {
    perror("Failed to write region 0\n");
    munmap(memspace, 0x01000000);
    close(ifdr);
    close(ofd);
    return -1;
  }
  close(ofd);
  printf("Unmapping memory space\n");
  munmap(memspace, 0x01000000);
  close(ifdr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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     11d8 <main+0x38>
cmpl   $0x4,-0x8(%rbp)
jle    1207 <main+0x67>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1491 <main+0x2f1>
cmpl   $0x3,-0x8(%rbp)
jl     122a <main+0x8a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10b0 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    124d <main+0xad>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10b0 <strtoul@plt>
mov    %eax,-0x20(%rbp)
mov    0x2d74(%rip),%rax
mov    (%rax),%esi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1288 <main+0xe8>
lea    0xdbe(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1491 <main+0x2f1>
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edx
mov    0x2cea(%rip),%rax
or     (%rax),%edx
mov    0x2d29(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x1000000,%esi
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    12f3 <main+0x153>
lea    0xd90(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1491 <main+0x2f1>
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     1319 <main+0x179>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
cmp    $0x1000000,%eax
jle    1335 <main+0x195>
mov    $0x1000000,%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xd3b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2c18(%rip),%rax
mov    (%rax),%esi
mov    0x2c8f(%rip),%rax
or     (%rax),%esi
mov    0x2c7e(%rip),%rax
or     (%rax),%esi
mov    0x2c0d(%rip),%rax
mov    (%rax),%edx
mov    0x2c3c(%rip),%rax
or     (%rax),%edx
mov    0x2c13(%rip),%rax
or     (%rax),%edx
mov    0x2c02(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1409 <main+0x269>
mov    0x2bfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2bde(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xcd5(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    $0x1000000,%esi
call   1080 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1491 <main+0x2f1>
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    -0x20(%rbp),%edx
call   1030 <write@plt>
cmp    -0x20(%rbp),%eax
je     145e <main+0x2be>
lea    0xcab(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x28(%rbp),%rdi
mov    $0x1000000,%esi
call   1080 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1491 <main+0x2f1>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
lea    0xc87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    $0x1000000,%esi
call   1080 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%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,%r13
mov    %edi,%ebx
lea    -0x5(%rbx),%eax
cmp    $0xfffffffc,%eax
ja     11eb <main+0x3b>
lea    0xf27(%rip),%rdi
call   1030 <puts@plt>
mov    0x0(%r13),%rsi
lea    0xe21(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    13b1 <main+0x201>
mov    $0x1000000,%r12d
xor    %r14d,%r14d
cmp    $0x3,%ebx
jb     122c <main+0x7c>
mov    0x10(%r13),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10c0 <strtoul@plt>
mov    %eax,%r14d
and    $0xfffffffc,%r14d
cmp    $0x4,%ebx
jne    122c <main+0x7c>
mov    0x18(%r13),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10c0 <strtoul@plt>
mov    %eax,%r12d
and    $0xfffffffc,%r12d
mov    0x2d95(%rip),%rax
mov    (%rax),%esi
lea    0xdf4(%rip),%rdi
xor    %eax,%eax
call   10a0 <open@plt>
test   %eax,%eax
js     13c5 <main+0x215>
mov    %eax,%ebp
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d88(%rip),%rax
mov    0x2d29(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d66(%rip),%rax
mov    (%rax),%ecx
mov    $0x1000000,%ebx
xor    %edi,%edi
mov    $0x1000000,%esi
mov    %ebp,0x4(%rsp)
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
test   %rax,%rax
je     13d3 <main+0x223>
mov    %rax,%r15
cmp    $0x1000000,%r14d
mov    $0x0,%eax
cmovge %eax,%r14d
lea    (%r14,%r12,1),%eax
sub    %r14d,%ebx
cmp    $0x1000001,%eax
cmovl  %r12d,%ebx
mov    0x8(%r13),%rcx
lea    0xd95(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2c9f(%rip),%rax
mov    0x2d18(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d05(%rip),%rax
or     (%rax),%esi
mov    0x2c94(%rip),%rax
mov    0x2cc5(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2c9a(%rip),%rax
or     (%rax),%edx
mov    0x8(%r13),%rdi
mov    0x2c85(%rip),%rax
or     (%rax),%edx
xor    %eax,%eax
call   10a0 <open@plt>
test   %eax,%eax
js     136c <main+0x1bc>
mov    %eax,%r12d
movslq %r14d,%rax
mov    %r15,%rsi
add    %rax,%rsi
mov    %r12d,%edi
mov    %ebx,%edx
call   1040 <write@plt>
cmp    %ebx,%eax
jne    13e1 <main+0x231>
mov    %r12d,%edi
call   1070 <close@plt>
lea    0xd92(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    $0x1000000,%esi
call   1090 <munmap@plt>
mov    0x4(%rsp),%edi
call   1070 <close@plt>
xor    %eax,%eax
jmp    13b6 <main+0x206>
mov    0x2c3d(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%r13),%rbp
mov    0x2c28(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xcff(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
call   1080 <fprintf@plt>
mov    %r15,%rdi
mov    $0x1000000,%esi
call   1090 <munmap@plt>
mov    0x4(%rsp),%edi
call   1070 <close@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc55(%rip),%rdi
call   10b0 <perror@plt>
jmp    13b1 <main+0x201>
lea    0xc66(%rip),%rdi
call   10b0 <perror@plt>
jmp    13a8 <main+0x1f8>
lea    0xcc8(%rip),%rdi
call   10b0 <perror@plt>
mov    %r15,%rdi
mov    $0x1000000,%esi
call   1090 <munmap@plt>
mov    0x4(%rsp),%edi
call   1070 <close@plt>
mov    %r12d,%edi
jmp    13ac <main+0x1fc>

LLVM IR (-O0):
@.str = [20 x i8] c"Dumps 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"
@.str.6 = [50 x i8] c"Writing 0x%x bytes starting at offset 0x%x to %s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@stderr = global i32 0
@.str.7 = [35 x i8] c"Failed to open output file %s: %s\0A\00"
@errno = global i32 0
@.str.8 = [26 x i8] c"Failed to write region 0\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 i8*
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
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 4
br i1 %15, label %16, label %22
16: ; preds = %13, %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %20)
store i32 -1, i32* %3
br label %135
22: ; preds = %13
%23 = load i32, i32* %4
%24 = icmp sge i32 %23, 3
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @strtoul(i8* %28, i32* null, i32 16)
store i32 %29, i32* %8
br label %30
30: ; preds = %25, %22
%31 = load i32, i32* %4
%32 = icmp eq i32 %31, 4
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 3
%36 = load i8*, i8** %35
%37 = call i32 @strtoul(i8* %36, i32* null, i32 16)
store i32 %37, i32* %9
br label %38
38: ; preds = %33, %30
%39 = load i32, i32* @O_RDWR
%40 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %39)
store i32 %40, i32* %6
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = 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 %135
44: ; preds = %38
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%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* %6
%51 = call i8* @mmap(i32 0, i32 16777216, i32 %48, i32 %49, i32 %50, i32 0)
store i8* %51, i8** %10
%52 = icmp ne i8* %51, null
br i1 %52, label %57, label %53
53: ; preds = %44
%54 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%55 = load i32, i32* %6
%56 = call i32 @close(i32 %55)
store i32 -1, i32* %3
br label %135
57: ; preds = %44
%58 = load i32, i32* %8
%59 = and i32 %58, -4
store i32 %59, i32* %8
%60 = load i32, i32* %9
%61 = and i32 %60, -4
store i32 %61, i32* %9
%62 = load i32, i32* %8
%63 = icmp sge i32 %62, 16777216
br i1 %63, label %64, label %65
64: ; preds = %57
store i32 0, i32* %8
br label %65
65: ; preds = %64, %57
%66 = load i32, i32* %8
%67 = load i32, i32* %9
%68 = add nsw i32 %66, %67
%69 = icmp sgt i32 %68, 16777216
br i1 %69, label %70, label %73
70: ; preds = %65
%71 = load i32, i32* %8
%72 = sub nsw i32 16777216, %71
store i32 %72, i32* %9
br label %73
73: ; preds = %70, %65
%74 = load i32, i32* %9
%75 = load i32, i32* %8
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 1
%78 = load i8*, i8** %77
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0), i32 %74, i32 %75, i8* %78)
%80 = load i8**, i8*** %5
%81 = getelementptr inbounds i8*, i8** %80, i64 1
%82 = load i8*, i8** %81
%83 = load i32, i32* @O_WRONLY
%84 = load i32, i32* @O_CREAT
%85 = or i32 %83, %84
%86 = load i32, i32* @O_TRUNC
%87 = or i32 %85, %86
%88 = load i32, i32* @S_IRUSR
%89 = load i32, i32* @S_IWUSR
%90 = or i32 %88, %89
%91 = load i32, i32* @S_IRGRP
%92 = or i32 %90, %91
%93 = load i32, i32* @S_IROTH
%94 = or i32 %92, %93
%95 = call i32 (i8*, i32, ...) @open(i8* %82, i32 %87, i32 %94)
store i32 %95, i32* %7
%96 = icmp slt i32 %95, 0
br i1 %96, label %97, label %109
97: ; preds = %73
%98 = load i32, i32* @stderr
%99 = load i8**, i8*** %5
%100 = getelementptr inbounds i8*, i8** %99, i64 1
%101 = load i8*, i8** %100
%102 = load i32, i32* @errno
%103 = call i8* @strerror(i32 %102)
%104 = call i32 @fprintf(i32 %98, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i8* %101, i8* %103)
%105 = load i8*, i8** %10
%106 = call i32 @munmap(i8* %105, i32 16777216)
%107 = load i32, i32* %6
%108 = call i32 @close(i32 %107)
store i32 -1, i32* %3
br label %135
109: ; preds = %73
%110 = load i32, i32* %7
%111 = load i8*, i8** %10
%112 = load i32, i32* %8
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds i8, i8* %111, i64 %113
%115 = load i32, i32* %9
%116 = call i32 @write(i32 %110, i8* %114, i32 %115)
%117 = load i32, i32* %9
%118 = icmp ne i32 %116, %117
br i1 %118, label %119, label %127
119: ; preds = %109
%120 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
%121 = load i8*, i8** %10
%122 = call i32 @munmap(i8* %121, i32 16777216)
%123 = load i32, i32* %6
%124 = call i32 @close(i32 %123)
%125 = load i32, i32* %7
%126 = call i32 @close(i32 %125)
store i32 -1, i32* %3
br label %135
127: ; preds = %109
%128 = load i32, i32* %7
%129 = call i32 @close(i32 %128)
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%131 = load i8*, i8** %10
%132 = call i32 @munmap(i8* %131, i32 16777216)
%133 = load i32, i32* %6
%134 = call i32 @close(i32 %133)
store i32 0, i32* %3
br label %135
135: ; preds = %127, %119, %97, %53, %42, %16
%136 = load i32, i32* %3
ret i32 %136
}

LLVM IR (-O2):
@.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"
@.str.6 = [50 x i8] c"Writing 0x%x bytes starting at offset 0x%x to %s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@stderr = global i32 0
@.str.7 = [35 x i8] c"Failed to open output file %s: %s\0A\00"
@errno = global i32 0
@.str.8 = [26 x i8] c"Failed to write region 0\0A\00"
@str = [21 x i8] c"Mapping memory space\00"
@str.10 = [23 x i8] c"Unmapping memory space\00"
@str.11 = [19 x i8] c"Dumps 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.11, 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 %89
9: ; preds = %2
%10 = icmp ugt i32 %0, 2
br i1 %10, label %11, label %22
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 %22
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)
%21 = and i32 %20, -4
br label %22
22: ; preds = %9, %17, %11
%23 = phi i32 [ %15, %17 ], [ %15, %11 ], [ 0, %9 ]
%24 = phi i32 [ %21, %17 ], [ 16777216, %11 ], [ 16777216, %9 ]
%25 = load i32, i32* @O_RDWR
%26 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %89
30: ; preds = %22
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%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 0, i32 16777216, i32 %34, i32 %35, i32 %26, i32 0)
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %41
38: ; preds = %30
%39 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%40 = tail call i32 @close(i32 %26)
br label %89
41: ; preds = %30
%42 = icmp sgt i32 %23, 16777215
%43 = select i1 %42, i32 0, i32 %23
%44 = add nsw i32 %43, %24
%45 = icmp sgt i32 %44, 16777216
%46 = sub nsw i32 16777216, %43
%47 = select i1 %45, i32 %46, i32 %24
%48 = getelementptr inbounds i8*, i8** %1, i64 1
%49 = load i8*, i8** %48
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0), i32 %47, i32 %43, i8* %49)
%51 = load i8*, i8** %48
%52 = load i32, i32* @O_WRONLY
%53 = load i32, i32* @O_CREAT
%54 = or i32 %53, %52
%55 = load i32, i32* @O_TRUNC
%56 = or i32 %54, %55
%57 = load i32, i32* @S_IRUSR
%58 = load i32, i32* @S_IWUSR
%59 = or i32 %58, %57
%60 = load i32, i32* @S_IRGRP
%61 = or i32 %59, %60
%62 = load i32, i32* @S_IROTH
%63 = or i32 %61, %62
%64 = tail call i32 (i8*, i32, ...) @open(i8* %51, i32 %56, i32 %63)
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %74
66: ; preds = %41
%67 = load i32, i32* @stderr
%68 = load i8*, i8** %48
%69 = load i32, i32* @errno
%70 = tail call i8* @strerror(i32 %69)
%71 = tail call i32 @fprintf(i32 %67, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i8* %68, i8* %70)
%72 = tail call i32 @munmap(i8* %36, i32 16777216)
%73 = tail call i32 @close(i32 %26)
br label %89
74: ; preds = %41
%75 = sext i32 %43 to i64
%76 = getelementptr inbounds i8, i8* %36, i64 %75
%77 = tail call i32 @write(i32 %64, i8* %76, i32 %47)
%78 = icmp eq i32 %77, %47
br i1 %78, label %84, label %79
79: ; preds = %74
%80 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
%81 = tail call i32 @munmap(i8* %36, i32 16777216)
%82 = tail call i32 @close(i32 %26)
%83 = tail call i32 @close(i32 %64)
br label %89
84: ; preds = %74
%85 = tail call i32 @close(i32 %64)
%86 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.10, i64 0, i64 0))
%87 = tail call i32 @munmap(i8* %36, i32 16777216)
%88 = tail call i32 @close(i32 %26)
br label %89
89: ; preds = %84, %79, %66, %38, %28, %5
%90 = phi i32 [ -1, %5 ], [ -1, %28 ], [ -1, %66 ], [ -1, %79 ], [ 0, %84 ], [ -1, %38 ]
ret i32 %90
}