#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 */

/* 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 write(int, unsigned char *, int);
int main(int argc, char *argv[]) {
  int ifdr, ifdu, ofd;
  unsigned char *regspace;
  unsigned char *unkspace;
  if (argc < 2 || argc > 3) {
    printf("Dumps tl880 registers and optionally the 64kb \"unknown purpose\" "
           "region\n");
    printf("Usage: %s reg_file [unk_file]\n", argv[0]);
    return -1;
  }
  if ((ifdr = open("/dev/tl880/reg0", O_RDWR)) < 0) {
    perror("Unable to open /dev/tl880/reg0");
    return -1;
  }
  if ((ifdu = open("/dev/tl880/unk0", O_RDWR)) < 0) {
    perror("Unable to open /dev/tl880/unk0");
    close(ifdr);
  }
  printf("Mapping register space\n");
  if (!(regspace =
            mmap(0, 0x00100000, PROT_READ | PROT_WRITE, MAP_SHARED, ifdr, 0))) {
    perror("Failed to mmap region 2 (reg)");
    close(ifdr);
    close(ifdu);
    return -1;
  }
  printf("Mapping unknown region\n");
  if (!(unkspace =
            mmap(0, 0x00010000, PROT_READ | PROT_WRITE, MAP_SHARED, ifdu, 0))) {
    perror("Failed to mmap region 3 (unk)");
    munmap(regspace, 0x00100000);
    close(ifdr);
    close(ifdu);
    return -1;
  }
  printf("Writing register space\n");
  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(regspace, 0x00100000);
    munmap(unkspace, 0x00010000);
    close(ifdr);
    close(ifdu);
    return -1;
  }
  if (write(ofd, regspace, 0x00100000) != 0x00100000) {
    perror("Failed to write region 2\n");
    munmap(regspace, 0x00100000);
    munmap(unkspace, 0x00010000);
    close(ifdr);
    close(ifdu);
    close(ofd);
    return -1;
  }
  close(ofd);
  if (argc == 3) {
    printf("Writing unknown region\n");
    if ((ofd = open(argv[2], 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[2],
              strerror(errno));
      munmap(regspace, 0x00100000);
      munmap(unkspace, 0x00010000);
      close(ifdr);
      close(ifdu);
      return -1;
    }
    if (write(ofd, unkspace, 0x00010000) != 0x00010000) {
      perror("Failed to write region 3\n");
      munmap(regspace, 0x00100000);
      munmap(unkspace, 0x00010000);
      close(ifdr);
      close(ifdu);
      close(ofd);
      return -1;
    }
    close(ofd);
  }
  printf("Unmapping register space\n");
  munmap(regspace, 0x00100000);
  printf("Unmapping unknown space\n");
  munmap(unkspace, 0x00010000);
  close(ifdr);
  close(ifdu);
  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)
cmpl   $0x2,-0x8(%rbp)
jl     11ba <main+0x2a>
cmpl   $0x3,-0x8(%rbp)
jle    11e9 <main+0x59>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1640 <main+0x4b0>
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1224 <main+0x94>
lea    0xe54(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1640 <main+0x4b0>
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    125b <main+0xcb>
lea    0xe38(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%edx
mov    0x2d17(%rip),%rax
or     (%rax),%edx
mov    0x2d56(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x100000,%esi
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    12ce <main+0x13e>
lea    0xe10(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1640 <main+0x4b0>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d05(%rip),%rax
mov    (%rax),%edx
mov    0x2ca4(%rip),%rax
or     (%rax),%edx
mov    0x2ce3(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x10000,%esi
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    134f <main+0x1bf>
lea    0xdd3(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x28(%rbp),%rdi
mov    $0x100000,%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    1640 <main+0x4b0>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2c0c(%rip),%rax
mov    (%rax),%esi
mov    0x2c83(%rip),%rax
or     (%rax),%esi
mov    0x2c72(%rip),%rax
or     (%rax),%esi
mov    0x2c01(%rip),%rax
mov    (%rax),%edx
mov    0x2c30(%rip),%rax
or     (%rax),%edx
mov    0x2c07(%rip),%rax
or     (%rax),%edx
mov    0x2bf6(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    142b <main+0x29b>
mov    0x2bf2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2bd2(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xd3b(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    $0x100000,%esi
call   1080 <munmap@plt>
mov    -0x30(%rbp),%rdi
mov    $0x10000,%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    1640 <main+0x4b0>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x100000,%edx
call   1030 <write@plt>
cmp    $0x100000,%eax
je     1493 <main+0x303>
lea    0xcfe(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x28(%rbp),%rdi
mov    $0x100000,%esi
call   1080 <munmap@plt>
mov    -0x30(%rbp),%rdi
mov    $0x10000,%esi
call   1080 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1640 <main+0x4b0>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
cmpl   $0x3,-0x8(%rbp)
jne    15f1 <main+0x461>
lea    0xcba(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2ab6(%rip),%rax
mov    (%rax),%esi
mov    0x2b2d(%rip),%rax
or     (%rax),%esi
mov    0x2b1c(%rip),%rax
or     (%rax),%esi
mov    0x2aab(%rip),%rax
mov    (%rax),%edx
mov    0x2ada(%rip),%rax
or     (%rax),%edx
mov    0x2ab1(%rip),%rax
or     (%rax),%edx
mov    0x2aa0(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1581 <main+0x3f1>
mov    0x2a9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    0x2a7c(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xbe5(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    $0x100000,%esi
call   1080 <munmap@plt>
mov    -0x30(%rbp),%rdi
mov    $0x10000,%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    1640 <main+0x4b0>
mov    -0x1c(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    $0x10000,%edx
call   1030 <write@plt>
cmp    $0x10000,%eax
je     15e9 <main+0x459>
lea    0xbda(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x28(%rbp),%rdi
mov    $0x100000,%esi
call   1080 <munmap@plt>
mov    -0x30(%rbp),%rdi
mov    $0x10000,%esi
call   1080 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1640 <main+0x4b0>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
lea    0xba0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    $0x100000,%esi
call   1080 <munmap@plt>
lea    0xb9e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    $0x10000,%esi
call   1080 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%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
sub    $0x18,%rsp
mov    %rsi,%r12
mov    %edi,%r15d
lea    -0x4(%r15),%eax
cmp    $0xfffffffd,%eax
ja     11e0 <main+0x40>
lea    0xfb9(%rip),%rdi
call   1030 <puts@plt>
mov    (%r12),%rsi
lea    0xe2c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1456 <main+0x2b6>
mov    0x2de1(%rip),%rbx
mov    (%rbx),%esi
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   10a0 <open@plt>
test   %eax,%eax
js     146a <main+0x2ca>
mov    %eax,%ebp
mov    (%rbx),%esi
lea    0xe43(%rip),%rdi
xor    %eax,%eax
call   10a0 <open@plt>
mov    %eax,0x8(%rsp)
test   %eax,%eax
js     1478 <main+0x2d8>
lea    0xecc(%rip),%rdi
call   1030 <puts@plt>
mov    0x2db8(%rip),%r14
mov    0x2d59(%rip),%r13
mov    0x0(%r13),%edx
or     (%r14),%edx
mov    0x2d93(%rip),%rbx
mov    (%rbx),%ecx
xor    %edi,%edi
mov    $0x100000,%esi
mov    %ebp,0xc(%rsp)
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     1490 <main+0x2f0>
lea    0xe95(%rip),%rdi
call   1030 <puts@plt>
mov    0x0(%r13),%edx
or     (%r14),%edx
mov    (%rbx),%ecx
xor    %edi,%edi
mov    $0x10000,%esi
mov    0x8(%rsp),%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
test   %rax,%rax
je     149e <main+0x2fe>
mov    %rax,%r13
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
mov    0x2cc5(%rip),%rax
mov    0x2d3e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d2b(%rip),%rax
or     (%rax),%esi
mov    0x2cba(%rip),%rax
mov    0x2ceb(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2cc0(%rip),%rbx
or     (%rbx),%edx
mov    0x8(%r12),%rdi
mov    0x2caa(%rip),%rbp
or     0x0(%rbp),%edx
xor    %eax,%eax
call   10a0 <open@plt>
test   %eax,%eax
js     13e8 <main+0x248>
mov    %eax,%r14d
mov    %eax,%edi
mov    0x10(%rsp),%rsi
mov    $0x100000,%edx
call   1040 <write@plt>
cmp    $0x100000,%eax
jne    14b6 <main+0x316>
mov    %r14d,%edi
call   1070 <close@plt>
cmp    $0x3,%r15d
jne    139e <main+0x1fe>
lea    0xe32(%rip),%rdi
call   1030 <puts@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%esi
mov    0x2c2f(%rip),%rax
or     (%rax),%esi
mov    0x2c9e(%rip),%rax
or     (%rax),%esi
mov    0x10(%r12),%rdi
mov    0x2c60(%rip),%rax
mov    (%rax),%edx
mov    0x2c1f(%rip),%rax
or     (%rax),%edx
or     (%rbx),%edx
or     0x0(%rbp),%edx
xor    %eax,%eax
call   10a0 <open@plt>
test   %eax,%eax
js     13f8 <main+0x258>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r13,%rsi
mov    $0x10000,%edx
call   1040 <write@plt>
cmp    $0x10000,%eax
jne    14f8 <main+0x358>
mov    %ebp,%edi
call   1070 <close@plt>
lea    0xd90(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%rdi
mov    $0x100000,%esi
call   1090 <munmap@plt>
lea    0xd8e(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
mov    $0x10000,%esi
call   1090 <munmap@plt>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
xor    %eax,%eax
jmp    145b <main+0x2bb>
mov    0x2bc1(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%r12),%rbx
jmp    1406 <main+0x266>
mov    0x2bb1(%rip),%rax
mov    (%rax),%ebp
mov    0x10(%r12),%rbx
mov    0x2b9b(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xc7e(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1080 <fprintf@plt>
mov    0x10(%rsp),%rdi
mov    $0x100000,%esi
call   1090 <munmap@plt>
mov    %r13,%rdi
mov    $0x10000,%esi
call   1090 <munmap@plt>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbae(%rip),%rdi
call   10b0 <perror@plt>
jmp    1456 <main+0x2b6>
lea    0xbbf(%rip),%rdi
call   10b0 <perror@plt>
mov    %ebp,%edi
call   1070 <close@plt>
jmp    121d <main+0x7d>
lea    0xbc6(%rip),%rdi
call   10b0 <perror@plt>
jmp    1444 <main+0x2a4>
lea    0xbd6(%rip),%rdi
call   10b0 <perror@plt>
mov    0x10(%rsp),%rdi
mov    $0x100000,%esi
jmp    143f <main+0x29f>
lea    0xbff(%rip),%rdi
call   10b0 <perror@plt>
mov    0x10(%rsp),%rdi
mov    $0x100000,%esi
call   1090 <munmap@plt>
mov    %r13,%rdi
mov    $0x10000,%esi
call   1090 <munmap@plt>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
mov    %r14d,%edi
jmp    1451 <main+0x2b1>
lea    0xbd7(%rip),%rdi
call   10b0 <perror@plt>
mov    0x10(%rsp),%rdi
mov    $0x100000,%esi
call   1090 <munmap@plt>
mov    %r13,%rdi
mov    $0x10000,%esi
call   1090 <munmap@plt>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
mov    %ebp,%edi
jmp    1451 <main+0x2b1>

LLVM IR (-O0):
@.str = [72 x i8] c"Dumps tl880 registers and optionally the 64kb \22unknown purpose\22 region\0A\00"
@.str.1 = [31 x i8] c"Usage: %s reg_file [unk_file]\0A\00"
@.str.2 = [16 x i8] c"/dev/tl880/reg0\00"
@O_RDWR = global i32 0
@.str.3 = [31 x i8] c"Unable to open /dev/tl880/reg0\00"
@.str.4 = [16 x i8] c"/dev/tl880/unk0\00"
@.str.5 = [31 x i8] c"Unable to open /dev/tl880/unk0\00"
@.str.6 = [24 x i8] c"Mapping register space\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.7 = [30 x i8] c"Failed to mmap region 2 (reg)\00"
@.str.8 = [24 x i8] c"Mapping unknown region\0A\00"
@.str.9 = [30 x i8] c"Failed to mmap region 3 (unk)\00"
@.str.10 = [24 x i8] c"Writing register space\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.11 = [35 x i8] c"Failed to open output file %s: %s\0A\00"
@errno = global i32 0
@.str.12 = [26 x i8] c"Failed to write region 2\0A\00"
@.str.13 = [24 x i8] c"Writing unknown region\0A\00"
@.str.14 = [26 x i8] c"Failed to write region 3\0A\00"
@.str.15 = [26 x i8] c"Unmapping register space\0A\00"
@.str.16 = [25 x i8] c"Unmapping unknown 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 i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%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, 3
br i1 %15, label %16, label %22
16: ; preds = %13, %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 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 ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %20)
store i32 -1, i32* %3
br label %191
22: ; preds = %13
%23 = load i32, i32* @O_RDWR
%24 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %23)
store i32 %24, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = 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 %191
28: ; preds = %22
%29 = load i32, i32* @O_RDWR
%30 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %29)
store i32 %30, i32* %7
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%34 = load i32, i32* %6
%35 = call i32 @close(i32 %34)
br label %36
36: ; preds = %32, %28
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%38 = load i32, i32* @PROT_READ
%39 = load i32, i32* @PROT_WRITE
%40 = or i32 %38, %39
%41 = load i32, i32* @MAP_SHARED
%42 = load i32, i32* %6
%43 = call i8* @mmap(i32 0, i32 1048576, i32 %40, i32 %41, i32 %42, i32 0)
store i8* %43, i8** %9
%44 = icmp ne i8* %43, null
br i1 %44, label %51, label %45
45: ; preds = %36
%46 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
%47 = load i32, i32* %6
%48 = call i32 @close(i32 %47)
%49 = load i32, i32* %7
%50 = call i32 @close(i32 %49)
store i32 -1, i32* %3
br label %191
51: ; preds = %36
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%53 = load i32, i32* @PROT_READ
%54 = load i32, i32* @PROT_WRITE
%55 = or i32 %53, %54
%56 = load i32, i32* @MAP_SHARED
%57 = load i32, i32* %7
%58 = call i8* @mmap(i32 0, i32 65536, i32 %55, i32 %56, i32 %57, i32 0)
store i8* %58, i8** %10
%59 = icmp ne i8* %58, null
br i1 %59, label %68, label %60
60: ; preds = %51
%61 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0))
%62 = load i8*, i8** %9
%63 = call i32 @munmap(i8* %62, i32 1048576)
%64 = load i32, i32* %6
%65 = call i32 @close(i32 %64)
%66 = load i32, i32* %7
%67 = call i32 @close(i32 %66)
store i32 -1, i32* %3
br label %191
68: ; preds = %51
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
%70 = load i8**, i8*** %5
%71 = getelementptr inbounds i8*, i8** %70, i64 1
%72 = load i8*, i8** %71
%73 = load i32, i32* @O_WRONLY
%74 = load i32, i32* @O_CREAT
%75 = or i32 %73, %74
%76 = load i32, i32* @O_TRUNC
%77 = or i32 %75, %76
%78 = load i32, i32* @S_IRUSR
%79 = load i32, i32* @S_IWUSR
%80 = or i32 %78, %79
%81 = load i32, i32* @S_IRGRP
%82 = or i32 %80, %81
%83 = load i32, i32* @S_IROTH
%84 = or i32 %82, %83
%85 = call i32 (i8*, i32, ...) @open(i8* %72, i32 %77, i32 %84)
store i32 %85, i32* %8
%86 = icmp slt i32 %85, 0
br i1 %86, label %87, label %103
87: ; preds = %68
%88 = load i32, i32* @stderr
%89 = load i8**, i8*** %5
%90 = getelementptr inbounds i8*, i8** %89, i64 1
%91 = load i8*, i8** %90
%92 = load i32, i32* @errno
%93 = call i8* @strerror(i32 %92)
%94 = call i32 @fprintf(i32 %88, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0), i8* %91, i8* %93)
%95 = load i8*, i8** %9
%96 = call i32 @munmap(i8* %95, i32 1048576)
%97 = load i8*, i8** %10
%98 = call i32 @munmap(i8* %97, i32 65536)
%99 = load i32, i32* %6
%100 = call i32 @close(i32 %99)
%101 = load i32, i32* %7
%102 = call i32 @close(i32 %101)
store i32 -1, i32* %3
br label %191
103: ; preds = %68
%104 = load i32, i32* %8
%105 = load i8*, i8** %9
%106 = call i32 @write(i32 %104, i8* %105, i32 1048576)
%107 = icmp ne i32 %106, 1048576
br i1 %107, label %108, label %120
108: ; preds = %103
%109 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0))
%110 = load i8*, i8** %9
%111 = call i32 @munmap(i8* %110, i32 1048576)
%112 = load i8*, i8** %10
%113 = call i32 @munmap(i8* %112, i32 65536)
%114 = load i32, i32* %6
%115 = call i32 @close(i32 %114)
%116 = load i32, i32* %7
%117 = call i32 @close(i32 %116)
%118 = load i32, i32* %8
%119 = call i32 @close(i32 %118)
store i32 -1, i32* %3
br label %191
120: ; preds = %103
%121 = load i32, i32* %8
%122 = call i32 @close(i32 %121)
%123 = load i32, i32* %4
%124 = icmp eq i32 %123, 3
br i1 %124, label %125, label %180
125: ; preds = %120
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.13, i64 0, i64 0))
%127 = load i8**, i8*** %5
%128 = getelementptr inbounds i8*, i8** %127, i64 2
%129 = load i8*, i8** %128
%130 = load i32, i32* @O_WRONLY
%131 = load i32, i32* @O_CREAT
%132 = or i32 %130, %131
%133 = load i32, i32* @O_TRUNC
%134 = or i32 %132, %133
%135 = load i32, i32* @S_IRUSR
%136 = load i32, i32* @S_IWUSR
%137 = or i32 %135, %136
%138 = load i32, i32* @S_IRGRP
%139 = or i32 %137, %138
%140 = load i32, i32* @S_IROTH
%141 = or i32 %139, %140
%142 = call i32 (i8*, i32, ...) @open(i8* %129, i32 %134, i32 %141)
store i32 %142, i32* %8
%143 = icmp slt i32 %142, 0
br i1 %143, label %144, label %160
144: ; preds = %125
%145 = load i32, i32* @stderr
%146 = load i8**, i8*** %5
%147 = getelementptr inbounds i8*, i8** %146, i64 2
%148 = load i8*, i8** %147
%149 = load i32, i32* @errno
%150 = call i8* @strerror(i32 %149)
%151 = call i32 @fprintf(i32 %145, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0), i8* %148, i8* %150)
%152 = load i8*, i8** %9
%153 = call i32 @munmap(i8* %152, i32 1048576)
%154 = load i8*, i8** %10
%155 = call i32 @munmap(i8* %154, i32 65536)
%156 = load i32, i32* %6
%157 = call i32 @close(i32 %156)
%158 = load i32, i32* %7
%159 = call i32 @close(i32 %158)
store i32 -1, i32* %3
br label %191
160: ; preds = %125
%161 = load i32, i32* %8
%162 = load i8*, i8** %10
%163 = call i32 @write(i32 %161, i8* %162, i32 65536)
%164 = icmp ne i32 %163, 65536
br i1 %164, label %165, label %177
165: ; preds = %160
%166 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.14, i64 0, i64 0))
%167 = load i8*, i8** %9
%168 = call i32 @munmap(i8* %167, i32 1048576)
%169 = load i8*, i8** %10
%170 = call i32 @munmap(i8* %169, i32 65536)
%171 = load i32, i32* %6
%172 = call i32 @close(i32 %171)
%173 = load i32, i32* %7
%174 = call i32 @close(i32 %173)
%175 = load i32, i32* %8
%176 = call i32 @close(i32 %175)
store i32 -1, i32* %3
br label %191
177: ; preds = %160
%178 = load i32, i32* %8
%179 = call i32 @close(i32 %178)
br label %180
180: ; preds = %177, %120
%181 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.15, i64 0, i64 0))
%182 = load i8*, i8** %9
%183 = call i32 @munmap(i8* %182, i32 1048576)
%184 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.16, i64 0, i64 0))
%185 = load i8*, i8** %10
%186 = call i32 @munmap(i8* %185, i32 65536)
%187 = load i32, i32* %6
%188 = call i32 @close(i32 %187)
%189 = load i32, i32* %7
%190 = call i32 @close(i32 %189)
store i32 0, i32* %3
br label %191
191: ; preds = %180, %165, %144, %108, %87, %60, %45, %26, %16
%192 = load i32, i32* %3
ret i32 %192
}

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