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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int atoi(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fp;
  int i = 0, start_addr = 0;
  char c;
  char *filename = "/etc/passwd";
  if (argc > 1)
    filename = argv[1];
  if (argc > 2)
    start_addr = atoi(argv[2]);
  printf("\n **** DISPLAYING (IN HEX) FILE: %s at offset = %d (=0x%x) ****\n\n",
         filename, start_addr, start_addr);
  if (!(fp = fopen(filename, "r"))) {
    perror(filename);
    exit(errno);
  };
  if (-1 == fseek(fp, start_addr, SEEK_SET)) {
    perror(filename);
    exit(errno);
  };
  printf("starting at 0x%x:\n", start_addr);
  while (!feof(fp)) {
    if (fread(&c, 1, 1, fp) < 0) {
      perror(filename);
      exit(errno);
    };
    printf("%2.2x ", c);
    if (i % 16 == 0)
      printf("\n");
    i++;
  }
  printf("\n");
  fclose(fp);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xe45(%rip),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11d5 <main+0x45>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11ef <main+0x5f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    123c <main+0xac>
mov    -0x30(%rbp),%rdi
call   1090 <perror@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    0x2d8e(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1277 <main+0xe7>
mov    -0x30(%rbp),%rdi
call   1090 <perror@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%esi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12a6 <main+0x116>
jmp    131d <main+0x18d>
mov    -0x18(%rbp),%rcx
lea    -0x21(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%rax
jge    12db <main+0x14b>
mov    -0x30(%rbp),%rdi
call   1090 <perror@plt>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
movsbl -0x21(%rbp),%esi
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    130f <main+0x17f>
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1288 <main+0xf8>
lea    0xd28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %ebp,%ebp
cmp    $0x2,%edi
jl     11c6 <main+0x26>
mov    0x8(%rsi),%r14
je     11cd <main+0x2d>
mov    0x10(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebp
jmp    11cd <main+0x2d>
lea    0xe33(%rip),%r14
lea    0xe38(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe65(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1211 <main+0x71>
mov    %rax,%rbx
mov    0x2dd8(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <fseek@plt>
cmp    $0xffffffff,%eax
jne    1227 <main+0x87>
mov    %r14,%rdi
call   10a0 <perror@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xe22(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    12aa <main+0x10a>
lea    0xf(%rsp),%r15
lea    0xe14(%rip),%r12
xor    %ebp,%ebp
jmp    126f <main+0xcf>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebp
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    12aa <main+0x10a>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
test   %rax,%rax
js     1211 <main+0x71>
movsbl 0xf(%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   $0xf,%bpl
jne    1260 <main+0xc0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1260 <main+0xc0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/etc/passwd\00"
@.str.1 = [66 x i8] c"\0A **** DISPLAYING (IN HEX) FILE: %s at offset = %d (=0x%x) ****\0A\0A\00"
@.str.2 = [2 x i8] c"r\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [19 x i8] c"starting at 0x%x:\0A\00"
@.str.4 = [7 x i8] c"%2.2x \00"
@.str.5 = [2 x i8] c"\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
store i32 0, i32* %7
store i32 0, i32* %8
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %10
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %10
br label %17
17: ; preds = %13, %2
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 2
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %8
br label %25
25: ; preds = %20, %17
%26 = load i8*, i8** %10
%27 = load i32, i32* %8
%28 = load i32, i32* %8
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32 %27, i32 %28)
%30 = load i8*, i8** %10
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %31, i32** %6
%32 = icmp ne i32* %31, null
br i1 %32, label %38, label %33
33: ; preds = %25
%34 = load i8*, i8** %10
%35 = call i32 @perror(i8* %34)
%36 = load i32, i32* @errno
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %25
%39 = load i32*, i32** %6
%40 = load i32, i32* %8
%41 = load i32, i32* @SEEK_SET
%42 = call i32 @fseek(i32* %39, i32 %40, i32 %41)
%43 = icmp eq i32 -1, %42
br i1 %43, label %44, label %49
44: ; preds = %38
%45 = load i8*, i8** %10
%46 = call i32 @perror(i8* %45)
%47 = load i32, i32* @errno
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %38
%50 = load i32, i32* %8
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %75, %49
%53 = load i32*, i32** %6
%54 = call i32 @feof(i32* %53)
%55 = icmp ne i32 %54, 0
%56 = xor i1 %55, true
br i1 %56, label %57, label %78
57: ; preds = %52
%58 = load i32*, i32** %6
%59 = call i64 @fread(i8* %9, i32 1, i32 1, i32* %58)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %66
61: ; preds = %57
%62 = load i8*, i8** %10
%63 = call i32 @perror(i8* %62)
%64 = load i32, i32* @errno
%65 = call i32 @exit(i32 %64)
unreachable
66: ; preds = %57
%67 = load i8, i8* %9
%68 = sext i8 %67 to i32
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %68)
%70 = load i32, i32* %7
%71 = srem i32 %70, 16
%72 = icmp eq i32 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %66
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %75
75: ; preds = %73, %66
%76 = load i32, i32* %7
%77 = add nsw i32 %76, 1
store i32 %77, i32* %7
br label %52
78: ; preds = %52
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%80 = load i32*, i32** %6
%81 = call i32 @fclose(i32* %80)
%82 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [12 x i8] c"/etc/passwd\00"
@.str.1 = [66 x i8] c"\0A **** DISPLAYING (IN HEX) FILE: %s at offset = %d (=0x%x) ****\0A\0A\00"
@.str.2 = [2 x i8] c"r\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [19 x i8] c"starting at 0x%x:\0A\00"
@.str.4 = [7 x i8] c"%2.2x \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %13
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = icmp eq i32 %0, 2
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
br label %13
13: ; preds = %2, %9, %5
%14 = phi i8* [ %7, %9 ], [ %7, %5 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %2 ]
%15 = phi i32 [ %12, %9 ], [ 0, %5 ], [ 0, %2 ]
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32 %15, i32 %15)
%17 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = tail call i32 @perror(i8* %14)
%21 = load i32, i32* @errno
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %13
%24 = load i32, i32* @SEEK_SET
%25 = tail call i32 @fseek(i32* %17, i32 %15, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = tail call i32 @perror(i8* %14)
%29 = load i32, i32* @errno
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %23
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%33 = tail call i32 @feof(i32* %17)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %55
35: ; preds = %31, %51
%36 = phi i32 [ %52, %51 ], [ 0, %31 ]
%37 = call i64 @fread(i8* %3, i32 1, i32 1, i32* %17)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = tail call i32 @perror(i8* %14)
%41 = load i32, i32* @errno
%42 = tail call i32 @exit(i32 %41)
unreachable
43: ; preds = %35
%44 = load i8, i8* %3
%45 = sext i8 %44 to i32
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %45)
%47 = and i32 %36, 15
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %43
%50 = tail call i32 @putchar(i32 10)
br label %51
51: ; preds = %49, %43
%52 = add nuw nsw i32 %36, 1
%53 = tail call i32 @feof(i32* %17)
%54 = icmp eq i32 %53, 0
br i1 %54, label %35, label %55
55: ; preds = %51, %31
%56 = tail call i32 @putchar(i32 10)
%57 = tail call i32 @fclose(i32* %17)
%58 = tail call i32 @exit(i32 0)
unreachable
}