#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
unsigned long str2long(int /*<<< orphan*/, char *);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ usage(int /*<<< orphan*/, int);
int main(int argc, char *argv[]) {
  int c;
  unsigned long start, end, inc, x;
  printf("Data CPLB replacement Test\n\n");
  start = 0x4000;
  inc = 0x1000;
  end = 0x8000;
  while ((c = getopt(argc, argv, "vch?s:e:i:")) > 0) {
    switch (c) {
    case 'v':
      printf("%s: version %s\n", argv[0], "0.1");
      exit(0);
    case 's':
      start = str2long(optarg, "s");
      break;
    case 'e':
      end = str2long(optarg, "e");
      break;
    case 'i':
      inc = str2long(optarg, "i");
      break;
    case 'h':
    case '?':
      usage(stdout, 0);
      break;
    default:
      fprintf(stderr, "ERROR: unkown option '%c'\n", c);
      usage(stderr, 1);
      break;
    }
  }
  printf("Start:\t 0x%X\n", start);
  printf("End:\t 0x%X\n", end);
  printf("Incr:\t 0x%X\n\n", inc);
  if (start >= end) {
    usage(stdout, 0);
    return 0;
  }
  for (x = start; x <= end; x += inc) {
    (void)((*(volatile unsigned char *)(x)));
  }
  printf("Test Success\n\n");
  system("cat /proc/cplbinfo");
  exit(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)
lea    0xf53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x4000,-0x20(%rbp)
movq   $0x1000,-0x30(%rbp)
movq   $0x8000,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xf43(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    12b6 <main+0x146>
mov    -0x14(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x37,%eax
ja     1286 <main+0x116>
mov    -0x40(%rbp),%rax
lea    0xe15(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xf06(%rip),%rdi
lea    0xf0f(%rip),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xef5(%rip),%rsi
call   1060 <str2long@plt>
mov    %rax,-0x20(%rbp)
jmp    12b1 <main+0x141>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
lea    0xed9(%rip),%rsi
call   1060 <str2long@plt>
mov    %rax,-0x28(%rbp)
jmp    12b1 <main+0x141>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
lea    0xebd(%rip),%rsi
call   1060 <str2long@plt>
mov    %rax,-0x30(%rbp)
jmp    12b1 <main+0x141>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1070 <usage@plt>
jmp    12b1 <main+0x141>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe89(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1070 <usage@plt>
jmp    11ac <main+0x3c>
mov    -0x20(%rbp),%rsi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jb     1312 <main+0x1a2>
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1070 <usage@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
ja     133f <main+0x1cf>
mov    -0x38(%rbp),%rax
mov    (%rax),%al
mov    -0x30(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    131a <main+0x1aa>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe20(%rip),%rdi
call   1030 <system@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %edi,%r14d
lea    0xfc0(%rip),%rdi
call   1030 <puts@plt>
lea    0xf39(%rip),%rdx
mov    %r14d,%edi
mov    %rbp,%rsi
call   1090 <getopt@plt>
test   %eax,%eax
jle    128d <main+0x10d>
mov    $0x4000,%ecx
mov    %rcx,(%rsp)
mov    $0x8000,%ecx
mov    %rcx,0x8(%rsp)
mov    $0x1000,%ecx
mov    %rcx,0x10(%rsp)
lea    0xf02(%rip),%rbx
lea    0xe1b(%rip),%r12
mov    0x2de4(%rip),%r15
mov    0x2e05(%rip),%r13
jmp    1231 <main+0xb1>
mov    0x2ddc(%rip),%rcx
mov    (%rcx),%edi
lea    0xf00(%rip),%rsi
mov    %eax,%edx
call   1060 <fprintf@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1080 <usage@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1090 <getopt@plt>
test   %eax,%eax
jle    12aa <main+0x12a>
lea    -0x3f(%rax),%ecx
cmp    $0x37,%ecx
ja     11f5 <main+0x75>
movslq (%r12,%rcx,4),%rcx
add    %r12,%rcx
jmp    *%rcx
mov    (%r15),%edi
xor    %esi,%esi
jmp    121a <main+0x9a>
mov    0x0(%r13),%edi
lea    0xead(%rip),%rsi
call   1070 <str2long@plt>
mov    %rax,0x8(%rsp)
jmp    121f <main+0x9f>
mov    0x0(%r13),%edi
lea    0xe98(%rip),%rsi
call   1070 <str2long@plt>
mov    %rax,0x10(%rsp)
jmp    121f <main+0x9f>
mov    0x0(%r13),%edi
lea    0xe7d(%rip),%rsi
call   1070 <str2long@plt>
mov    %rax,(%rsp)
jmp    121f <main+0x9f>
mov    $0x1000,%eax
mov    %rax,0x10(%rsp)
mov    $0x8000,%eax
mov    %rax,0x8(%rsp)
mov    $0x4000,%eax
mov    %rax,(%rsp)
lea    0xe6f(%rip),%rdi
mov    (%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe68(%rip),%rdi
mov    0x8(%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe5e(%rip),%rdi
mov    0x10(%rsp),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %rbp,%rbx
jb     1320 <main+0x1a0>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1080 <usage@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
add    %r14,%rbx
cmp    %rbp,%rbx
jbe    1320 <main+0x1a0>
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
lea    0xe0a(%rip),%rdi
call   1040 <system@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    0x0(%rbp),%rsi
lea    0xd96(%rip),%rdi
lea    0xd9f(%rip),%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"Data CPLB replacement Test\0A\0A\00"
@.str.1 = [11 x i8] c"vch?s:e:i:\00"
@.str.2 = [16 x i8] c"%s: version %s\0A\00"
@.str.3 = [4 x i8] c"0.1\00"
@optarg = global i32 0
@.str.4 = [2 x i8] c"s\00"
@.str.5 = [2 x i8] c"e\00"
@.str.6 = [2 x i8] c"i\00"
@stdout = global i32 0
@stderr = global i32 0
@.str.7 = [27 x i8] c"ERROR: unkown option '%c'\0A\00"
@.str.8 = [14 x i8] c"Start:\09 0x%X\0A\00"
@.str.9 = [12 x i8] c"End:\09 0x%X\0A\00"
@.str.10 = [14 x i8] c"Incr:\09 0x%X\0A\0A\00"
@.str.11 = [15 x i8] c"Test Success\0A\0A\00"
@.str.12 = [19 x i8] c"cat /proc/cplbinfo\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i64 16384, i64* %7
store i64 4096, i64* %9
store i64 32768, i64* %8
br label %12
12: ; preds = %43, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 %15, i32* %6
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %44
17: ; preds = %12
%18 = load i32, i32* %6
switch i32 %18, label %37 [
i32 118, label %19
i32 115, label %25
i32 101, label %28
i32 105, label %31
i32 104, label %34
i32 63, label %34
]
19: ; preds = %17
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %17
%26 = load i32, i32* @optarg
%27 = call i64 @str2long(i32 %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i64 %27, i64* %7
br label %43
28: ; preds = %17
%29 = load i32, i32* @optarg
%30 = call i64 @str2long(i32 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i64 %30, i64* %8
br label %43
31: ; preds = %17
%32 = load i32, i32* @optarg
%33 = call i64 @str2long(i32 %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i64 %33, i64* %9
br label %43
34: ; preds = %17, %17
%35 = load i32, i32* @stdout
%36 = call i32 @usage(i32 %35, i32 0)
br label %43
37: ; preds = %17
%38 = load i32, i32* @stderr
%39 = load i32, i32* %6
%40 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %39)
%41 = load i32, i32* @stderr
%42 = call i32 @usage(i32 %41, i32 1)
br label %43
43: ; preds = %37, %34, %31, %28, %25
br label %12
44: ; preds = %12
%45 = load i64, i64* %7
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i64 %45)
%47 = load i64, i64* %8
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i64 %47)
%49 = load i64, i64* %9
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i64 %49)
%51 = load i64, i64* %7
%52 = load i64, i64* %8
%53 = icmp uge i64 %51, %52
br i1 %53, label %54, label %57
54: ; preds = %44
%55 = load i32, i32* @stdout
%56 = call i32 @usage(i32 %55, i32 0)
ret i32 0
57: ; preds = %44
%58 = load i64, i64* %7
store i64 %58, i64* %10
br label %59
59: ; preds = %67, %57
%60 = load i64, i64* %10
%61 = load i64, i64* %8
%62 = icmp ule i64 %60, %61
br i1 %62, label %63, label %71
63: ; preds = %59
%64 = load i64, i64* %10
%65 = inttoptr i64 %64 to i8*
%66 = load volatile i8, i8* %65
br label %67
67: ; preds = %63
%68 = load i64, i64* %9
%69 = load i64, i64* %10
%70 = add i64 %69, %68
store i64 %70, i64* %10
br label %59
71: ; preds = %59
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
%73 = call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0))
%74 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [11 x i8] c"vch?s:e:i:\00"
@.str.2 = [16 x i8] c"%s: version %s\0A\00"
@.str.3 = [4 x i8] c"0.1\00"
@optarg = global i32 0
@.str.4 = [2 x i8] c"s\00"
@.str.5 = [2 x i8] c"e\00"
@.str.6 = [2 x i8] c"i\00"
@stdout = global i32 0
@stderr = global i32 0
@.str.7 = [27 x i8] c"ERROR: unkown option '%c'\0A\00"
@.str.8 = [14 x i8] c"Start:\09 0x%X\0A\00"
@.str.9 = [12 x i8] c"End:\09 0x%X\0A\00"
@.str.10 = [14 x i8] c"Incr:\09 0x%X\0A\0A\00"
@.str.12 = [19 x i8] c"cat /proc/cplbinfo\00"
@str = [28 x i8] c"Data CPLB replacement Test\0A\00"
@str.13 = [14 x i8] c"Test Success\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %38
6: ; preds = %2, %32
%7 = phi i32 [ %36, %32 ], [ %4, %2 ]
%8 = phi i64 [ %35, %32 ], [ 4096, %2 ]
%9 = phi i64 [ %34, %32 ], [ 32768, %2 ]
%10 = phi i64 [ %33, %32 ], [ 16384, %2 ]
switch i32 %7, label %27 [
i32 118, label %11
i32 115, label %15
i32 101, label %18
i32 105, label %21
i32 104, label %24
i32 63, label %24
]
11: ; preds = %6
%12 = load i8*, i8** %1
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %6
%16 = load i32, i32* @optarg
%17 = tail call i64 @str2long(i32 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %32
18: ; preds = %6
%19 = load i32, i32* @optarg
%20 = tail call i64 @str2long(i32 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %32
21: ; preds = %6
%22 = load i32, i32* @optarg
%23 = tail call i64 @str2long(i32 %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %32
24: ; preds = %6, %6
%25 = load i32, i32* @stdout
%26 = tail call i32 @usage(i32 %25, i32 0)
br label %32
27: ; preds = %6
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %7)
%30 = load i32, i32* @stderr
%31 = tail call i32 @usage(i32 %30, i32 1)
br label %32
32: ; preds = %27, %24, %21, %18, %15
%33 = phi i64 [ %10, %27 ], [ %10, %24 ], [ %10, %21 ], [ %10, %18 ], [ %17, %15 ]
%34 = phi i64 [ %9, %27 ], [ %9, %24 ], [ %9, %21 ], [ %20, %18 ], [ %9, %15 ]
%35 = phi i64 [ %8, %27 ], [ %8, %24 ], [ %23, %21 ], [ %8, %18 ], [ %8, %15 ]
%36 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp sgt i32 %36, 0
br i1 %37, label %6, label %38
38: ; preds = %32, %2
%39 = phi i64 [ 16384, %2 ], [ %33, %32 ]
%40 = phi i64 [ 32768, %2 ], [ %34, %32 ]
%41 = phi i64 [ 4096, %2 ], [ %35, %32 ]
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i64 %39)
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i64 %40)
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i64 %41)
%45 = icmp ult i64 %39, %40
br i1 %45, label %49, label %46
46: ; preds = %38
%47 = load i32, i32* @stdout
%48 = tail call i32 @usage(i32 %47, i32 0)
ret i32 0
49: ; preds = %38, %49
%50 = phi i64 [ %53, %49 ], [ %39, %38 ]
%51 = inttoptr i64 %50 to i8*
%52 = load volatile i8, i8* %51
%53 = add i64 %50, %41
%54 = icmp ugt i64 %53, %40
br i1 %54, label %55, label %49
55: ; preds = %49
%56 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.13, i64 0, i64 0))
%57 = tail call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0))
%58 = tail call i32 @exit(i32 0)
unreachable
}