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

/* Variables and functions */
int /*<<< orphan*/ *MAP_FAILED;
int MAP_POPULATE;
int MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ comp(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
unsigned int filesize(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ *mmap(int /*<<< orphan*/ *, unsigned int, int /*<<< orphan*/,
                         int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main() {
  char *input = "testfile";
  unsigned int i, inputsize = filesize(input);
  unsigned int int_count = inputsize;
  int_count -= (int_count % sizeof(uint64_t));
  int_count /= sizeof(uint64_t);
  int ifd = open(input, O_RDONLY);
  if (ifd < 0) {
    fprintf(stderr, "Error opening");
    exit(1);
  }
  uint64_t *mem;
  mem = mmap(NULL, inputsize, PROT_READ, MAP_PRIVATE | MAP_POPULATE, ifd, 0);
  if (mem == MAP_FAILED) {
    fprintf(stderr, "Error mmapping");
    exit(1);
  }
  for (i = 0; i < int_count; i++) {
    printf("%hhX\n", comp(mem[i]));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <filesize@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
and    $0x3,%rcx
mov    -0x1c(%rbp),%eax
sub    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
shr    $0x2,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11f6 <main+0x86>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%esi
mov    0x2df8(%rip),%rax
mov    (%rax),%edx
mov    0x2db7(%rip),%rax
mov    (%rax),%ecx
mov    0x2dc6(%rip),%rax
or     (%rax),%ecx
mov    -0x20(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2d85(%rip),%rcx
cmp    (%rcx),%rax
jne    125b <main+0xeb>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    1299 <main+0x129>
mov    -0x28(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,4),%edi
call   1030 <comp@plt>
mov    %eax,%esi
lea    0xda0(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1262 <main+0xf2>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe82(%rip),%rbx
mov    %rbx,%rdi
call   1080 <filesize@plt>
mov    %eax,%r14d
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
test   %eax,%eax
js     1229 <main+0xb9>
mov    0x2e4f(%rip),%rcx
mov    (%rcx),%edx
mov    0x2e0e(%rip),%rsi
mov    0x2e1f(%rip),%rcx
mov    (%rcx),%ecx
or     (%rsi),%ecx
xor    %edi,%edi
mov    %r14d,%esi
mov    %eax,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%r15
mov    0x2de1(%rip),%rax
cmp    (%rax),%r15
je     123b <main+0xcb>
cmp    $0x4,%r14d
jb     121c <main+0xac>
shr    $0x2,%r14d
cmp    $0x2,%r14d
mov    $0x1,%ebp
cmovae %r14d,%ebp
xor    %ebx,%ebx
lea    0xe2a(%rip),%r14
nopl   0x0(%rax)
mov    (%r15,%rbx,4),%edi
call   1030 <comp@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1200 <main+0x90>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
jmp    124b <main+0xdb>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"testfile\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [14 x i8] c"Error opening\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_POPULATE = global i32 0
@MAP_FAILED = global i32* null
@.str.2 = [15 x i8] c"Error mmapping\00"
@.str.3 = [6 x i8] c"%hhX\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @filesize(i8* %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = zext i32 %11 to i64
%13 = urem i64 %12, 4
%14 = load i32, i32* %5
%15 = zext i32 %14 to i64
%16 = sub i64 %15, %13
%17 = trunc i64 %16 to i32
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = zext i32 %18 to i64
%20 = udiv i64 %19, 4
%21 = trunc i64 %20 to i32
store i32 %21, i32* %5
%22 = load i8*, i8** %2
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %0
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %0
%32 = load i32, i32* %4
%33 = load i32, i32* @PROT_READ
%34 = load i32, i32* @MAP_PRIVATE
%35 = load i32, i32* @MAP_POPULATE
%36 = or i32 %34, %35
%37 = load i32, i32* %6
%38 = call i32* @mmap(i32* null, i32 %32, i32 %33, i32 %36, i32 %37, i32 0)
store i32* %38, i32** %7
%39 = load i32*, i32** %7
%40 = load i32*, i32** @MAP_FAILED
%41 = icmp eq i32* %39, %40
br i1 %41, label %42, label %46
42: ; preds = %31
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %31
store i32 0, i32* %3
br label %47
47: ; preds = %59, %46
%48 = load i32, i32* %3
%49 = load i32, i32* %5
%50 = icmp ult i32 %48, %49
br i1 %50, label %51, label %62
51: ; preds = %47
%52 = load i32*, i32** %7
%53 = load i32, i32* %3
%54 = zext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %52, i64 %54
%56 = load i32, i32* %55
%57 = call i32 @comp(i32 %56)
%58 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %51
%60 = load i32, i32* %3
%61 = add i32 %60, 1
store i32 %61, i32* %3
br label %47
62: ; preds = %47
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"testfile\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [14 x i8] c"Error opening\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_POPULATE = global i32 0
@MAP_FAILED = global i32* null
@.str.2 = [15 x i8] c"Error mmapping\00"
@.str.3 = [6 x i8] c"%hhX\0A\00"
define i32 @main() {
%1 = tail call i32 @filesize(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%2 = lshr i32 %1, 2
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i32, i32* @PROT_READ
%12 = load i32, i32* @MAP_PRIVATE
%13 = load i32, i32* @MAP_POPULATE
%14 = or i32 %13, %12
%15 = tail call i32* @mmap(i32* null, i32 %1, i32 %11, i32 %14, i32 %4, i32 0)
%16 = load i32*, i32** @MAP_FAILED
%17 = icmp eq i32* %15, %16
br i1 %17, label %23, label %18
18: ; preds = %10
%19 = icmp ult i32 %1, 4
br i1 %19, label %35, label %20
20: ; preds = %18
%21 = call i32 @llvm.umax.i32(i32 %2, i32 1)
%22 = zext i32 %21 to i64
br label %27
23: ; preds = %10
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %20, %27
%28 = phi i64 [ 0, %20 ], [ %33, %27 ]
%29 = getelementptr inbounds i32, i32* %15, i64 %28
%30 = load i32, i32* %29
%31 = tail call i32 @comp(i32 %30)
%32 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = add nuw nsw i64 %28, 1
%34 = icmp eq i64 %33, %22
br i1 %34, label %35, label %27
35: ; preds = %27, %18
ret i32 0
}