#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 /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_RDWR;
int O_SYNC;
int PROT_READ;
int PROT_WRITE;
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, ...);
int /*<<< orphan*/ *mmap(int /*<<< orphan*/, int, int, int /*<<< orphan*/, int,
                         int);
int open(char *, int);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int ch;
  int index;
  int model = 0;
  int type = 0;
  int ps = 0;
  uint8_t *vaddr;
  int fd;
  if (argc == 1)
    usage();
  while ((ch = getopt(argc, argv, "hm:pt:")) != -1) {
    switch (ch) {
    case 'm':
      model = atoi(optarg);
      break;
    case 'p':
      ps = 1;
      break;
    case 't':
      type = atoi(optarg);
      break;
    case 'h':
      usage();
      break;
    case '?':
      exit(1);
    default:
      break;
    }
  }
  if (type < 0 || type > 128) {
    fprintf(stderr, "Error program type!\n");
    exit(1);
  }
  fd = open("/dev/mem", O_RDWR | O_SYNC);
  if (fd == -1) {
    fprintf(stderr, "Error when opening /dev/mem\n");
    exit(1);
  }
  vaddr = mmap(0, 0x1000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0xf0002000);
  close(fd);
  if (vaddr == MAP_FAILED) {
    fprintf(stderr, "Error when mmap /dev/mem\n");
    exit(1);
  }
  for (index = optind; index < argc; index++) {
    printf("Traced program: %s\n", argv[index]);
    memcpy(vaddr + (2 << 2), &type, 4);
    memcpy(vaddr + (3 << 2), &argv[index], 4);
  }
  if (model > 0) {
    switch (model) {
    case 1:
      fprintf(stderr, "Timing model: pipeline simulation\n");
      break;
    case 2:
      fprintf(stderr, "Timing model: Pipeline and I/D cache simulation\n");
      break;
    case 3:
      fprintf(stderr,
              "Timing model: Pipeline, I/D cache and instruction simulation\n");
      break;
    default:
      fprintf(stderr, "Wrong timing model!\n");
      exit(1);
    }
    memcpy(vaddr + (1 << 2), &model, 4);
  }
  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   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11dc <main+0x3c>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    11e1 <main+0x41>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe11(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     12b0 <main+0x110>
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0x3f,%eax
je     129c <main+0xfc>
jmp    1214 <main+0x74>
mov    -0x38(%rbp),%eax
sub    $0x68,%eax
je     1290 <main+0xf0>
jmp    1225 <main+0x85>
mov    -0x38(%rbp),%eax
sub    $0x6d,%eax
je     1258 <main+0xb8>
jmp    1236 <main+0x96>
mov    -0x38(%rbp),%eax
sub    $0x70,%eax
je     126e <main+0xce>
jmp    1247 <main+0xa7>
mov    -0x38(%rbp),%eax
sub    $0x74,%eax
je     127a <main+0xda>
jmp    12a6 <main+0x106>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
call   10b0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    12ab <main+0x10b>
movl   $0x1,-0x24(%rbp)
jmp    12ab <main+0x10b>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
call   10b0 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    12ab <main+0x10b>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    12ab <main+0x10b>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    12ab <main+0x10b>
jmp    11e1 <main+0x41>
cmpl   $0x0,-0x20(%rbp)
jl     12c7 <main+0x127>
cmpl   $0x80,-0x20(%rbp)
jle    12e6 <main+0x146>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
lea    0xd30(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2ce3(%rip),%rax
mov    (%rax),%esi
mov    0x2cd2(%rip),%rax
or     (%rax),%esi
lea    0xd1d(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    1330 <main+0x190>
mov    0x2c98(%rip),%rax
mov    (%rax),%edi
lea    0xd04(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2cb9(%rip),%rax
mov    (%rax),%edx
mov    0x2c68(%rip),%rax
or     (%rax),%edx
mov    0x2c97(%rip),%rax
mov    (%rax),%ecx
mov    -0x34(%rbp),%r8d
xor    %edi,%edi
mov    $0x1000,%esi
mov    $0xf0002000,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
mov    -0x30(%rbp),%rax
mov    0x2c28(%rip),%rcx
cmp    (%rcx),%rax
jne    13a0 <main+0x200>
mov    0x2c28(%rip),%rax
mov    (%rax),%edi
lea    0xcb1(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2c19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1419 <main+0x279>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xc91(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
add    $0x20,%rdi
xor    %eax,%eax
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
mov    -0x30(%rbp),%rdi
add    $0x30,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
xor    %eax,%eax
mov    $0x4,%edx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    13ac <main+0x20c>
cmpl   $0x0,-0x1c(%rbp)
jle    14de <main+0x33e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x1,%eax
je     1459 <main+0x2b9>
jmp    1437 <main+0x297>
mov    -0x3c(%rbp),%eax
sub    $0x2,%eax
je     1473 <main+0x2d3>
jmp    1448 <main+0x2a8>
mov    -0x3c(%rbp),%eax
sub    $0x3,%eax
je     148d <main+0x2ed>
jmp    14a7 <main+0x307>
mov    0x2b50(%rip),%rax
mov    (%rax),%edi
lea    0xc07(%rip),%rsi
call   1060 <fprintf@plt>
jmp    14c6 <main+0x326>
mov    0x2b36(%rip),%rax
mov    (%rax),%edi
lea    0xc10(%rip),%rsi
call   1060 <fprintf@plt>
jmp    14c6 <main+0x326>
mov    0x2b1c(%rip),%rax
mov    (%rax),%edi
lea    0xc27(%rip),%rsi
call   1060 <fprintf@plt>
jmp    14c6 <main+0x326>
mov    0x2b02(%rip),%rax
mov    (%rax),%edi
lea    0xc4b(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x30(%rbp),%rdi
add    $0x10,%rdi
xor    %eax,%eax
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
xor    %eax,%eax
add    $0x40,%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
cmp    $0x1,%edi
jne    11bf <main+0x1f>
xor    %eax,%eax
call   1080 <usage@plt>
lea    0xe3a(%rip),%r15
mov    0x2e2b(%rip),%r14
xor    %r13d,%r13d
xor    %r12d,%r12d
jmp    11e7 <main+0x47>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1080 <usage@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   10a0 <getopt@plt>
cmp    $0x6c,%eax
jg     1210 <main+0x70>
cmp    $0x68,%eax
je     11e0 <main+0x40>
cmp    $0xffffffff,%eax
je     1234 <main+0x94>
cmp    $0x3f,%eax
jne    11e7 <main+0x47>
jmp    1396 <main+0x1f6>
nopl   (%rax)
cmp    $0x74,%eax
je     1227 <main+0x87>
cmp    $0x6d,%eax
jne    11e7 <main+0x47>
mov    (%r14),%edi
call   10b0 <atoi@plt>
mov    %eax,%r13d
jmp    11e7 <main+0x47>
mov    (%r14),%edi
call   10b0 <atoi@plt>
mov    %eax,%r12d
jmp    11e7 <main+0x47>
mov    %r12d,0x8(%rsp)
mov    %r13d,0xc(%rsp)
cmp    $0x81,%r12d
jae    13a0 <main+0x200>
mov    0x2d7e(%rip),%rax
mov    0x2d6f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xdb8(%rip),%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     13b2 <main+0x212>
mov    %eax,%r14d
mov    %r13d,0x4(%rsp)
mov    0x2d6f(%rip),%rax
mov    0x2d20(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d4d(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x1000,%esi
mov    %r14d,%r8d
mov    $0xf0002000,%r9d
call   1030 <mmap@plt>
mov    %rax,%r15
mov    %r14d,%edi
call   1050 <close@plt>
mov    0x2ce4(%rip),%rax
mov    %r15,0x10(%rsp)
cmp    (%rax),%r15
je     13c4 <main+0x224>
mov    0x2cef(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jge    1339 <main+0x199>
mov    0x10(%rsp),%rcx
lea    0x20(%rcx),%r12
lea    0x30(%rcx),%r13
movslq %ebp,%r15
lea    (%rbx,%rax,8),%rbx
sub    %rax,%r15
lea    0xd66(%rip),%rbp
lea    0x8(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rsi
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1070 <memcpy@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1070 <memcpy@plt>
add    $0x8,%rbx
add    $0xffffffffffffffff,%r15
jne    1300 <main+0x160>
mov    0x4(%rsp),%eax
test   %eax,%eax
jle    1385 <main+0x1e5>
add    $0xffffffff,%eax
cmp    $0x3,%eax
jae    13d6 <main+0x236>
cltq
lea    0xdc2(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
mov    0x2c4c(%rip),%rax
mov    (%rax),%edi
call   1060 <fprintf@plt>
mov    0x10(%rsp),%rdi
add    $0x10,%rdi
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1070 <memcpy@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2c09(%rip),%rax
mov    (%rax),%edi
lea    0xc57(%rip),%rsi
jmp    13e6 <main+0x246>
mov    0x2bf7(%rip),%rax
mov    (%rax),%edi
lea    0xc63(%rip),%rsi
jmp    13e6 <main+0x246>
mov    0x2be5(%rip),%rax
mov    (%rax),%edi
lea    0xc6e(%rip),%rsi
jmp    13e6 <main+0x246>
mov    0x2bd3(%rip),%rax
mov    (%rax),%edi
lea    0xd1c(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"hm:pt:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"Error program type!\0A\00"
@.str.2 = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@.str.3 = [29 x i8] c"Error when opening /dev/mem\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i32* null
@.str.4 = [26 x i8] c"Error when mmap /dev/mem\0A\00"
@optind = global i32 0
@.str.5 = [20 x i8] c"Traced program: %s\0A\00"
@.str.6 = [35 x i8] c"Timing model: pipeline simulation\0A\00"
@.str.7 = [49 x i8] c"Timing model: Pipeline and I/D cache simulation\0A\00"
@.str.8 = [62 x i8] c"Timing model: Pipeline, I/D cache and instruction simulation\0A\00"
@.str.9 = [21 x i8] c"Wrong timing model!\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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (...) @usage()
br label %17
17: ; preds = %15, %2
br label %18
18: ; preds = %37, %17
%19 = load i32, i32* %4
%20 = load i8**, i8*** %5
%21 = call i32 @getopt(i32 %19, i8** %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %21, i32* %6
%22 = icmp ne i32 %21, -1
br i1 %22, label %23, label %38
23: ; preds = %18
%24 = load i32, i32* %6
switch i32 %24, label %36 [
i32 109, label %25
i32 112, label %28
i32 116, label %29
i32 104, label %32
i32 63, label %34
]
25: ; preds = %23
%26 = load i32, i32* @optarg
%27 = call i32 @atoi(i32 %26)
store i32 %27, i32* %8
br label %37
28: ; preds = %23
store i32 1, i32* %10
br label %37
29: ; preds = %23
%30 = load i32, i32* @optarg
%31 = call i32 @atoi(i32 %30)
store i32 %31, i32* %9
br label %37
32: ; preds = %23
%33 = call i32 (...) @usage()
br label %37
34: ; preds = %23
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %23
br label %37
37: ; preds = %36, %32, %29, %28, %25
br label %18
38: ; preds = %18
%39 = load i32, i32* %9
%40 = icmp slt i32 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = load i32, i32* %9
%43 = icmp sgt i32 %42, 128
br i1 %43, label %44, label %48
44: ; preds = %41, %38
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %41
%49 = load i32, i32* @O_RDWR
%50 = load i32, i32* @O_SYNC
%51 = or i32 %49, %50
%52 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %51)
store i32 %52, i32* %12
%53 = load i32, i32* %12
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %59
55: ; preds = %48
%56 = load i32, i32* @stderr
%57 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %48
%60 = load i32, i32* @PROT_READ
%61 = load i32, i32* @PROT_WRITE
%62 = or i32 %60, %61
%63 = load i32, i32* @MAP_SHARED
%64 = load i32, i32* %12
%65 = call i32* @mmap(i32 0, i32 4096, i32 %62, i32 %63, i32 %64, i32 -268427264)
store i32* %65, i32** %11
%66 = load i32, i32* %12
%67 = call i32 @close(i32 %66)
%68 = load i32*, i32** %11
%69 = load i32*, i32** @MAP_FAILED
%70 = icmp eq i32* %68, %69
br i1 %70, label %71, label %75
71: ; preds = %59
%72 = load i32, i32* @stderr
%73 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%74 = call i32 @exit(i32 1)
unreachable
75: ; preds = %59
%76 = load i32, i32* @optind
store i32 %76, i32* %7
br label %77
77: ; preds = %98, %75
%78 = load i32, i32* %7
%79 = load i32, i32* %4
%80 = icmp slt i32 %78, %79
br i1 %80, label %81, label %101
81: ; preds = %77
%82 = load i8**, i8*** %5
%83 = load i32, i32* %7
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8*, i8** %82, i64 %84
%86 = load i8*, i8** %85
%87 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %86)
%88 = load i32*, i32** %11
%89 = getelementptr inbounds i32, i32* %88, i64 8
%90 = call i32 (i32*, ...) @memcpy(i32* %89, i32* %9, i32 4)
%91 = load i32*, i32** %11
%92 = getelementptr inbounds i32, i32* %91, i64 12
%93 = load i8**, i8*** %5
%94 = load i32, i32* %7
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8*, i8** %93, i64 %95
%97 = call i32 (i32*, ...) @memcpy(i32* %92, i8** %96, i32 4)
br label %98
98: ; preds = %81
%99 = load i32, i32* %7
%100 = add nsw i32 %99, 1
store i32 %100, i32* %7
br label %77
101: ; preds = %77
%102 = load i32, i32* %8
%103 = icmp sgt i32 %102, 0
br i1 %103, label %104, label %123
104: ; preds = %101
%105 = load i32, i32* %8
switch i32 %105, label %115 [
i32 1, label %106
i32 2, label %109
i32 3, label %112
]
106: ; preds = %104
%107 = load i32, i32* @stderr
%108 = call i32 @fprintf(i32 %107, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0))
br label %119
109: ; preds = %104
%110 = load i32, i32* @stderr
%111 = call i32 @fprintf(i32 %110, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0))
br label %119
112: ; preds = %104
%113 = load i32, i32* @stderr
%114 = call i32 @fprintf(i32 %113, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.8, i64 0, i64 0))
br label %119
115: ; preds = %104
%116 = load i32, i32* @stderr
%117 = call i32 @fprintf(i32 %116, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%118 = call i32 @exit(i32 1)
unreachable
119: ; preds = %112, %109, %106
%120 = load i32*, i32** %11
%121 = getelementptr inbounds i32, i32* %120, i64 4
%122 = call i32 (i32*, ...) @memcpy(i32* %121, i32* %8, i32 4)
br label %123
123: ; preds = %119, %101
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"hm:pt:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"Error program type!\0A\00"
@.str.2 = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@.str.3 = [29 x i8] c"Error when opening /dev/mem\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i32* null
@.str.4 = [26 x i8] c"Error when mmap /dev/mem\0A\00"
@optind = global i32 0
@.str.5 = [20 x i8] c"Traced program: %s\0A\00"
@.str.6 = [35 x i8] c"Timing model: pipeline simulation\0A\00"
@.str.7 = [49 x i8] c"Timing model: Pipeline and I/D cache simulation\0A\00"
@.str.8 = [62 x i8] c"Timing model: Pipeline, I/D cache and instruction simulation\0A\00"
@.str.9 = [21 x i8] c"Wrong timing model!\0A\00"
@reltable.main = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([35 x i8]* @.str.6 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([49 x i8]* @.str.7 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([62 x i8]* @.str.8 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32)]
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i32 %0, 1
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 (...) @usage()
br label %10
10: ; preds = %8, %2
br label %11
11: ; preds = %10, %19
%12 = phi i32 [ 0, %10 ], [ %21, %19 ]
%13 = phi i32 [ 0, %10 ], [ %15, %19 ]
br label %14
14: ; preds = %11, %22
%15 = phi i32 [ %13, %11 ], [ %24, %22 ]
br label %16
16: ; preds = %18, %14
%17 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
switch i32 %17, label %18 [
i32 -1, label %29
i32 109, label %19
i32 63, label %27
i32 116, label %22
i32 104, label %25
]
18: ; preds = %16, %25
br label %16
19: ; preds = %16
%20 = load i32, i32* @optarg
%21 = tail call i32 @atoi(i32 %20)
br label %11
22: ; preds = %16
%23 = load i32, i32* @optarg
%24 = tail call i32 @atoi(i32 %23)
br label %14
25: ; preds = %16
%26 = tail call i32 (...) @usage()
br label %18
27: ; preds = %16
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %16
store i32 %15, i32* %4
store i32 %12, i32* %3
%30 = icmp ugt i32 %15, 128
br i1 %30, label %31, label %35
31: ; preds = %29
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %29
%36 = load i32, i32* @O_RDWR
%37 = load i32, i32* @O_SYNC
%38 = or i32 %37, %36
%39 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %45
41: ; preds = %35
%42 = load i32, i32* @stderr
%43 = tail call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %35
%46 = load i32, i32* @PROT_READ
%47 = load i32, i32* @PROT_WRITE
%48 = or i32 %47, %46
%49 = load i32, i32* @MAP_SHARED
%50 = tail call i32* @mmap(i32 0, i32 4096, i32 %48, i32 %49, i32 %39, i32 -268427264)
%51 = tail call i32 @close(i32 %39)
%52 = load i32*, i32** @MAP_FAILED
%53 = icmp eq i32* %50, %52
br i1 %53, label %54, label %58
54: ; preds = %45
%55 = load i32, i32* @stderr
%56 = tail call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%57 = tail call i32 @exit(i32 1)
unreachable
58: ; preds = %45
%59 = load i32, i32* @optind
%60 = icmp slt i32 %59, %0
br i1 %60, label %61, label %75
61: ; preds = %58
%62 = getelementptr inbounds i32, i32* %50, i64 8
%63 = getelementptr inbounds i32, i32* %50, i64 12
%64 = sext i32 %59 to i64
%65 = sext i32 %0 to i64
br label %66
66: ; preds = %61, %66
%67 = phi i64 [ %64, %61 ], [ %73, %66 ]
%68 = getelementptr inbounds i8*, i8** %1, i64 %67
%69 = load i8*, i8** %68
%70 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %69)
%71 = call i32 (i32*, ...) @memcpy(i32* %62, i32* %4, i32 4)
%72 = call i32 (i32*, ...) @memcpy(i32* %63, i8** %68, i32 4)
%73 = add nsw i64 %67, 1
%74 = icmp eq i64 %73, %65
br i1 %74, label %75, label %66
75: ; preds = %66, %58
%76 = icmp sgt i32 %12, 0
br i1 %76, label %77, label %92
77: ; preds = %75
%78 = add i32 %12, -1
%79 = icmp ult i32 %78, 3
br i1 %79, label %84, label %80
80: ; preds = %77
%81 = load i32, i32* @stderr
%82 = call i32 @fprintf(i32 %81, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %77
%85 = sext i32 %78 to i64
%86 = shl i64 %85, 2
%87 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.main to i8*), i64 %86)
%88 = load i32, i32* @stderr
%89 = call i32 @fprintf(i32 %88, i8* %87)
%90 = getelementptr inbounds i32, i32* %50, i64 4
%91 = call i32 (i32*, ...) @memcpy(i32* %90, i32* %3, i32 4)
br label %92
92: ; preds = %84, %75
ret i32 0
}