#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*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  FILE *f;
  int i;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s [filename]\n", argv[0]);
    return 1;
  }
  f = fopen(argv[1], "rb");
  if (!f) {
    fprintf(stderr, "Could not open %s\n", argv[1]);
    return 1;
  }
  i = 0;
  while (1) {
    int c = fgetc(f);
    if (c < 0) {
      break;
    }
    if (!(i & 15)) {
      if (i) {
        printf("\n");
      }
      printf("        HEX    ");
    }
    printf(" %02X", c);
    ++i;
  }
  if (i != 0) {
    printf("\n");
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1198 <main+0x48>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1282 <main+0x132>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e4 <main+0x94>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe46(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1282 <main+0x132>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1206 <main+0xb6>
jmp    125a <main+0x10a>
mov    -0x1c(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    123b <main+0xeb>
cmpl   $0x0,-0x1c(%rbp)
je     122d <main+0xdd>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%esi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11eb <main+0x9b>
cmpl   $0x0,-0x1c(%rbp)
je     1272 <main+0x122>
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
cmp    $0x1,%edi
jg     118c <main+0x2c>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xe79(%rip),%rsi
jmp    125c <main+0xfc>
mov    0x8(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1248 <main+0xe8>
mov    %rax,%r13
mov    %rax,%rdi
call   1060 <fgetc@plt>
test   %eax,%eax
js     1277 <main+0x117>
mov    %eax,%r14d
lea    0xe6a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe6c(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
call   1060 <fgetc@plt>
test   %eax,%eax
js     126d <main+0x10d>
mov    %eax,%ebp
mov    $0x1,%ebx
lea    0xe34(%rip),%r15
lea    0xe3d(%rip),%r12
jmp    122d <main+0xcd>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebx
mov    %r13,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1268 <main+0x108>
test   $0xf,%bl
jne    1210 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1210 <main+0xb0>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xdbd(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%eax
jmp    1281 <main+0x121>
test   %r14d,%r14d
js     1277 <main+0x117>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Usage: %s [filename]\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [19 x i8] c"Could not open %s\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [16 x i8] c" HEX \00"
@.str.5 = [6 x i8] c" %02X\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %61
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp ne i32* %22, null
br i1 %23, label %30, label %24
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %28)
store i32 1, i32* %3
br label %61
30: ; preds = %17
store i32 0, i32* %7
br label %31
31: ; preds = %30, %48
%32 = load i32*, i32** %6
%33 = call i32 @fgetc(i32* %32)
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %31
br label %53
37: ; preds = %31
%38 = load i32, i32* %7
%39 = and i32 %38, 15
%40 = icmp ne i32 %39, 0
br i1 %40, label %48, label %41
41: ; preds = %37
%42 = load i32, i32* %7
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %46
46: ; preds = %44, %41
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %48
48: ; preds = %46, %37
%49 = load i32, i32* %8
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %31
53: ; preds = %36
%54 = load i32, i32* %7
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %53
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %58
58: ; preds = %56, %53
%59 = load i32*, i32** %6
%60 = call i32 @fclose(i32* %59)
store i32 0, i32* %3
br label %61
61: ; preds = %58, %24, %11
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Usage: %s [filename]\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [19 x i8] c"Could not open %s\0A\00"
@.str.4 = [16 x i8] c" HEX \00"
@.str.5 = [6 x i8] c" %02X\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %43
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %21, label %13
13: ; preds = %8
%14 = tail call i32 @fgetc(i32* %11)
%15 = icmp slt i32 %14, 0
br i1 %15, label %41, label %16
16: ; preds = %13
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %14)
%19 = tail call i32 @fgetc(i32* %11)
%20 = icmp slt i32 %19, 0
br i1 %20, label %39, label %25
21: ; preds = %8
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %9
%24 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %43
25: ; preds = %16, %33
%26 = phi i32 [ %36, %33 ], [ %19, %16 ]
%27 = phi i32 [ %35, %33 ], [ 1, %16 ]
%28 = and i32 %27, 15
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = tail call i32 @putchar(i32 10)
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %25, %30
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%35 = add nuw nsw i32 %27, 1
%36 = tail call i32 @fgetc(i32* %11)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %25
38: ; preds = %33
br i1 %15, label %41, label %39
39: ; preds = %16, %38
%40 = tail call i32 @putchar(i32 10)
br label %41
41: ; preds = %13, %39, %38
%42 = tail call i32 @fclose(i32* %11)
br label %43
43: ; preds = %41, %21, %4
%44 = phi i32 [ 1, %4 ], [ 0, %41 ], [ 1, %21 ]
ret i32 %44
}