#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  FILE *input_file;
  unsigned char line[16 + 1];
  unsigned int line_counter;
  int line_sz, ind, end_of_file;
  char *filename = argv[1];
  if (!(input_file = fopen(filename, "r"))) {
    fprintf(stderr,
            "Usage: hex <filename>\nRead a binary file. Pierre Dejoue 2001.\n");
    exit(1);
  }
  line_counter = 0;
  line[16] = '\0';
  end_of_file = 0;
  while (end_of_file == 0) {
    line_sz = fread(line, 1, 16, input_file);
    if (line_sz != 16)
      end_of_file = 1;
    printf("%08x ", line_counter * 16);
    for (ind = 0; ind < 16; ind++) {
      if (ind % 4 == 0)
        printf(" ");
      if (ind < line_sz)
        printf("%02x", line[ind]);
      else
        printf("  ");
    }
    for (ind = 0; ind < 16; ind++)
      if (ind < line_sz) {
        if (line[ind] < 32 || line[ind] > 126)
          line[ind] = '.';
      } else {
        line[ind] = '\0';
      }
    printf("    %s\n", line);
    line_counter++;
  }
  fclose(input_file);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11bf <main+0x5f>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0x34(%rbp)
movb   $0x0,-0x20(%rbp)
movl   $0x0,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jne    1321 <main+0x1c1>
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10,%edx
call   1030 <fread@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x10,-0x38(%rbp)
je     1206 <main+0xa6>
movl   $0x1,-0x40(%rbp)
mov    -0x34(%rbp),%esi
shl    $0x4,%esi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x10,-0x3c(%rbp)
jge    1296 <main+0x136>
mov    -0x3c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    124d <main+0xed>
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x3c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    1275 <main+0x115>
movslq -0x3c(%rbp),%rax
movzbl -0x30(%rbp,%rax,1),%esi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1283 <main+0x123>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1288 <main+0x128>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1221 <main+0xc1>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x10,-0x3c(%rbp)
jge    1301 <main+0x1a1>
mov    -0x3c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    12e5 <main+0x185>
movslq -0x3c(%rbp),%rax
movzbl -0x30(%rbp,%rax,1),%eax
cmp    $0x20,%eax
jl     12d7 <main+0x177>
movslq -0x3c(%rbp),%rax
movzbl -0x30(%rbp,%rax,1),%eax
cmp    $0x7e,%eax
jle    12e0 <main+0x180>
movslq -0x3c(%rbp),%rax
movb   $0x2e,-0x30(%rbp,%rax,1)
jmp    12ee <main+0x18e>
movslq -0x3c(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
jmp    12f3 <main+0x193>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    129d <main+0x13d>
lea    -0x30(%rbp),%rsi
lea    0xd43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11d1 <main+0x71>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    0x8(%rsi),%rdi
lea    0xe77(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,0x30(%rsp)
test   %rax,%rax
jne    11b7 <main+0x47>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movb   $0x0,0x20(%rsp)
lea    0x10(%rsp),%rbx
lea    0xe7f(%rip),%r15
lea    0xe7d(%rip),%rbp
xor    %r13d,%r13d
jmp    1205 <main+0x95>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xe68(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r13d
cmpl   $0x10,0xc(%rsp)
jne    1300 <main+0x190>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x10,%edx
mov    0x30(%rsp),%rcx
call   1040 <fread@plt>
mov    %eax,%ebx
mov    %r13d,%esi
shl    $0x4,%esi
lea    0xe16(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,0xc(%rsp)
movslq %ebx,%r14
xor    %r12d,%r12d
jmp    1254 <main+0xe4>
xchg   %ax,%ax
mov    %rbp,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r12
cmp    $0x10,%r12
je     12a0 <main+0x130>
test   $0x3,%r12b
je     1270 <main+0x100>
cmp    %r14,%r12
jge    1240 <main+0xd0>
jmp    127f <main+0x10f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x20,%edi
call   1030 <putchar@plt>
cmp    %r14,%r12
jge    1240 <main+0xd0>
movzbl 0x10(%rsp,%r12,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    124a <main+0xda>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
jmp    12c7 <main+0x157>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %edx,%edx
mov    %dl,0x11(%rsp,%rax,1)
add    $0x1,%rcx
mov    %rcx,%rax
cmp    $0x10,%rcx
je     11e0 <main+0x70>
cmp    %r14,%rax
jge    12e0 <main+0x170>
movzbl 0x10(%rsp,%rax,1),%edx
add    $0x81,%dl
mov    $0x2e,%cl
cmp    $0xa0,%dl
jbe    12e2 <main+0x172>
jmp    12e6 <main+0x176>
nopl   (%rax)
xor    %ecx,%ecx
mov    %cl,0x10(%rsp,%rax,1)
lea    0x1(%rax),%rcx
cmp    %r14,%rcx
jge    12b0 <main+0x140>
movzbl 0x11(%rsp,%rax,1),%ebx
add    $0x81,%bl
mov    $0x2e,%dl
cmp    $0xa0,%bl
jbe    12b2 <main+0x142>
jmp    12b6 <main+0x146>
mov    0x30(%rsp),%rdi
call   1050 <fclose@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [63 x i8] c"Usage: hex <filename>\0ARead a binary file. Pierre Dejoue 2001.\0A\00"
@.str.2 = [6 x i8] c"%08x \00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [5 x i8] c"%02x\00"
@.str.5 = [3 x i8] c" \00"
@.str.6 = [8 x i8] c" %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [17 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
store i8* %15, i8** %12
%16 = load i8*, i8** %12
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %6
%18 = icmp ne i32* %17, null
br i1 %18, label %23, label %19
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
store i32 0, i32* %8
%24 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 16
store i8 0, i8* %24
store i32 0, i32* %11
br label %25
25: ; preds = %100, %23
%26 = load i32, i32* %11
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %105
28: ; preds = %25
%29 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%30 = load i32*, i32** %6
%31 = call i32 @fread(i8* %29, i32 1, i32 16, i32* %30)
store i32 %31, i32* %9
%32 = load i32, i32* %9
%33 = icmp ne i32 %32, 16
br i1 %33, label %34, label %35
34: ; preds = %28
store i32 1, i32* %11
br label %35
35: ; preds = %34, %28
%36 = load i32, i32* %8
%37 = mul i32 %36, 16
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %37)
store i32 0, i32* %10
br label %39
39: ; preds = %62, %35
%40 = load i32, i32* %10
%41 = icmp slt i32 %40, 16
br i1 %41, label %42, label %65
42: ; preds = %39
%43 = load i32, i32* %10
%44 = srem i32 %43, 4
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %46, %42
%49 = load i32, i32* %10
%50 = load i32, i32* %9
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %59
52: ; preds = %48
%53 = load i32, i32* %10
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %57)
br label %61
59: ; preds = %48
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %61
61: ; preds = %59, %52
br label %62
62: ; preds = %61
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 1
store i32 %64, i32* %10
br label %39
65: ; preds = %39
store i32 0, i32* %10
br label %66
66: ; preds = %97, %65
%67 = load i32, i32* %10
%68 = icmp slt i32 %67, 16
br i1 %68, label %69, label %100
69: ; preds = %66
%70 = load i32, i32* %10
%71 = load i32, i32* %9
%72 = icmp slt i32 %70, %71
br i1 %72, label %73, label %92
73: ; preds = %69
%74 = load i32, i32* %10
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 %75
%77 = load i8, i8* %76
%78 = zext i8 %77 to i32
%79 = icmp slt i32 %78, 32
br i1 %79, label %87, label %80
80: ; preds = %73
%81 = load i32, i32* %10
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 %82
%84 = load i8, i8* %83
%85 = zext i8 %84 to i32
%86 = icmp sgt i32 %85, 126
br i1 %86, label %87, label %91
87: ; preds = %80, %73
%88 = load i32, i32* %10
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 %89
store i8 46, i8* %90
br label %91
91: ; preds = %87, %80
br label %96
92: ; preds = %69
%93 = load i32, i32* %10
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 %94
store i8 0, i8* %95
br label %96
96: ; preds = %92, %91
br label %97
97: ; preds = %96
%98 = load i32, i32* %10
%99 = add nsw i32 %98, 1
store i32 %99, i32* %10
br label %66
100: ; preds = %66
%101 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %101)
%103 = load i32, i32* %8
%104 = add i32 %103, 1
store i32 %104, i32* %8
br label %25
105: ; preds = %25
%106 = load i32*, i32** %6
%107 = call i32 @fclose(i32* %106)
%108 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [63 x i8] c"Usage: hex <filename>\0ARead a binary file. Pierre Dejoue 2001.\0A\00"
@.str.2 = [6 x i8] c"%08x \00"
@.str.4 = [5 x i8] c"%02x\00"
@.str.5 = [3 x i8] c" \00"
@.str.6 = [8 x i8] c" %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [17 x i8]
%4 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 16
store i8 0, i8* %14
br label %15
15: ; preds = %13, %62
%16 = phi i32 [ 0, %13 ], [ %65, %62 ]
%17 = call i32 @fread(i8* %4, i32 1, i32 16, i32* %7)
%18 = shl i32 %16, 4
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = sext i32 %17 to i64
br label %21
21: ; preds = %15, %36
%22 = phi i64 [ 0, %15 ], [ %37, %36 ]
%23 = and i64 %22, 3
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @putchar(i32 32)
br label %27
27: ; preds = %25, %21
%28 = icmp slt i64 %22, %20
br i1 %28, label %29, label %34
29: ; preds = %27
%30 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %22
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %32)
br label %36
34: ; preds = %27
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %36
36: ; preds = %29, %34
%37 = add nuw nsw i64 %22, 1
%38 = icmp eq i64 %37, 16
br i1 %38, label %39, label %21
39: ; preds = %36, %59
%40 = phi i64 [ %60, %59 ], [ 0, %36 ]
%41 = icmp slt i64 %40, %20
%42 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %40
br i1 %41, label %43, label %47
43: ; preds = %39
%44 = load i8, i8* %42
%45 = add i8 %44, -127
%46 = icmp ult i8 %45, -95
br i1 %46, label %47, label %49
47: ; preds = %39, %43
%48 = phi i8 [ 46, %43 ], [ 0, %39 ]
store i8 %48, i8* %42
br label %49
49: ; preds = %47, %43
%50 = or i64 %40, 1
%51 = icmp slt i64 %50, %20
%52 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %50
br i1 %51, label %53, label %57
53: ; preds = %49
%54 = load i8, i8* %52
%55 = add i8 %54, -127
%56 = icmp ult i8 %55, -95
br i1 %56, label %57, label %59
57: ; preds = %53, %49
%58 = phi i8 [ 46, %53 ], [ 0, %49 ]
store i8 %58, i8* %52
br label %59
59: ; preds = %57, %53
%60 = add nuw nsw i64 %40, 2
%61 = icmp eq i64 %60, 16
br i1 %61, label %62, label %39
62: ; preds = %59
%63 = icmp eq i32 %17, 16
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%65 = add i32 %16, 1
br i1 %63, label %15, label %66
66: ; preds = %62
%67 = call i32 @fclose(i32* %7)
%68 = call i32 @exit(i32 0)
unreachable
}