#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 EOF;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *ins;
  unsigned long pos;
  int c;
  char str[17];
  if (argc != 2) {
    fprintf(stderr, "usage: btoh <input_binary_file>\n");
    return 1;
  }
  ins = fopen(argv[1], "rb");
  if (ins == NULL) {
    perror("Couldn't open <input_binary_file>\n");
    return 1;
  }
  str[16] = '\0';
  pos = 0;
  while ((c = fgetc(ins)) != EOF) {
    if ((pos & 0xF) == 0)
      printf("%08lX:", pos);
    printf(" %02X", c);
    str[pos & 0xF] = ((0x20 <= c && c <= 0x7E) ? (char)c : '.');
    ++pos;
    if ((pos & 0xF) == 0)
      printf(" | %s\n", str);
  }
  if ((pos & 0xF) != 0) {
    for (; (pos & 0xF) != 0; ++pos) {
      printf("   ");
      str[pos & 0xF] = '\0';
    }
    printf(" | %s\n", str);
  }
  return 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)
cmpl   $0x2,-0x8(%rbp)
je     1191 <main+0x41>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    130f <main+0x1bf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe81(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11cc <main+0x7c>
lea    0xe69(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    130f <main+0x1bf>
movb   $0x0,-0x30(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2dfd(%rip),%rcx
cmp    (%rcx),%eax
je     12a1 <main+0x151>
mov    -0x20(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    1217 <main+0xc7>
mov    -0x20(%rbp),%rsi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x20,%eax
cmp    -0x24(%rbp),%eax
jg     124e <main+0xfe>
cmpl   $0x7e,-0x24(%rbp)
jg     124e <main+0xfe>
mov    -0x24(%rbp),%eax
movsbl %al,%eax
mov    %eax,-0x44(%rbp)
jmp    125b <main+0x10b>
mov    $0x2e,%eax
mov    %eax,-0x44(%rbp)
jmp    125b <main+0x10b>
mov    -0x44(%rbp),%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
and    $0xf,%rax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    129c <main+0x14c>
lea    -0x40(%rbp),%rsi
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d8 <main+0x88>
mov    -0x20(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
je     1308 <main+0x1b8>
jmp    12b8 <main+0x168>
mov    -0x20(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
je     12f6 <main+0x1a6>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
and    $0xf,%rax
movb   $0x0,-0x40(%rbp,%rax,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    12b8 <main+0x168>
lea    -0x40(%rbp),%rsi
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    1227 <main+0xd7>
mov    0x8(%rsi),%rdi
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     12ac <main+0x15c>
mov    %rax,%rbx
movb   $0x0,0x10(%rsp)
mov    %rax,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
mov    0x2e4f(%rip),%rax
xor    %r14d,%r14d
cmp    (%rax),%ebp
je     129a <main+0x14a>
mov    $0x1,%r14d
lea    0xe9d(%rip),%r15
mov    $0x2e,%r13d
jmp    11d9 <main+0x89>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
add    $0x1,%r14
mov    0x2e13(%rip),%rax
cmp    (%rax),%ebp
je     1244 <main+0xf4>
lea    -0x1(%r14),%rsi
mov    %rsi,%r12
and    $0xf,%r12
jne    11f4 <main+0xa4>
lea    0xe5a(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    -0x20(%rbp),%eax
cmp    $0x5f,%eax
cmovae %r13d,%ebp
mov    %bpl,(%rsp,%r12,1)
test   $0xf,%r14b
jne    11c0 <main+0x70>
lea    0xe39(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11c0 <main+0x70>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%r14d
jmp    129a <main+0x14a>
lea    -0x1(%r14),%ebp
and    $0xf,%rbp
je     1297 <main+0x147>
lea    0xe06(%rip),%r15
mov    %r14,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movb   $0x0,(%rsp,%rbp,1)
mov    %r14d,%ebp
and    $0xf,%ebp
add    $0x1,%rbx
test   $0xf,%r14b
mov    %rbx,%r14
jne    1260 <main+0x110>
lea    0xdcc(%rip),%rdi
xor    %r14d,%r14d
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    129a <main+0x14a>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd71(%rip),%rdi
call   1070 <perror@plt>
jmp    123c <main+0xec>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"usage: btoh <input_binary_file>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [35 x i8] c"Couldn't open <input_binary_file>\0A\00"
@EOF = global i32 0
@.str.3 = [7 x i8] c"%08lX:\00"
@.str.4 = [6 x i8] c" %02X\00"
@.str.5 = [7 x i8] c" | %s\0A\00"
@.str.6 = [4 x i8] c" \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 i32
%9 = alloca [17 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %87
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %87
24: ; preds = %15
%25 = getelementptr inbounds [17 x i8], [17 x i8]* %9, i64 0, i64 16
store i8 0, i8* %25
store i64 0, i64* %7
br label %26
26: ; preds = %65, %24
%27 = load i32*, i32** %6
%28 = call i32 @fgetc(i32* %27)
store i32 %28, i32* %8
%29 = load i32, i32* @EOF
%30 = icmp ne i32 %28, %29
br i1 %30, label %31, label %66
31: ; preds = %26
%32 = load i64, i64* %7
%33 = and i64 %32, 15
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = load i64, i64* %7
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 %36)
br label %38
38: ; preds = %35, %31
%39 = load i32, i32* %8
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %8
%42 = icmp sle i32 32, %41
br i1 %42, label %43, label %50
43: ; preds = %38
%44 = load i32, i32* %8
%45 = icmp sle i32 %44, 126
br i1 %45, label %46, label %50
46: ; preds = %43
%47 = load i32, i32* %8
%48 = trunc i32 %47 to i8
%49 = sext i8 %48 to i32
br label %51
50: ; preds = %43, %38
br label %51
51: ; preds = %50, %46
%52 = phi i32 [ %49, %46 ], [ 46, %50 ]
%53 = trunc i32 %52 to i8
%54 = load i64, i64* %7
%55 = and i64 %54, 15
%56 = getelementptr inbounds [17 x i8], [17 x i8]* %9, i64 0, i64 %55
store i8 %53, i8* %56
%57 = load i64, i64* %7
%58 = add i64 %57, 1
store i64 %58, i64* %7
%59 = load i64, i64* %7
%60 = and i64 %59, 15
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %51
%63 = getelementptr inbounds [17 x i8], [17 x i8]* %9, i64 0, i64 0
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %62, %51
br label %26
66: ; preds = %26
%67 = load i64, i64* %7
%68 = and i64 %67, 15
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %86
70: ; preds = %66
br label %71
71: ; preds = %80, %70
%72 = load i64, i64* %7
%73 = and i64 %72, 15
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %83
75: ; preds = %71
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%77 = load i64, i64* %7
%78 = and i64 %77, 15
%79 = getelementptr inbounds [17 x i8], [17 x i8]* %9, i64 0, i64 %78
store i8 0, i8* %79
br label %80
80: ; preds = %75
%81 = load i64, i64* %7
%82 = add i64 %81, 1
store i64 %82, i64* %7
br label %71
83: ; preds = %71
%84 = getelementptr inbounds [17 x i8], [17 x i8]* %9, i64 0, i64 0
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %84)
br label %86
86: ; preds = %83, %66
store i32 0, i32* %3
br label %87
87: ; preds = %86, %22, %12
%88 = load i32, i32* %3
ret i32 %88
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"usage: btoh <input_binary_file>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [35 x i8] c"Couldn't open <input_binary_file>\0A\00"
@EOF = global i32 0
@.str.3 = [7 x i8] c"%08lX:\00"
@.str.4 = [6 x i8] c" %02X\00"
@.str.5 = [7 x i8] c" | %s\0A\00"
@.str.6 = [4 x i8] c" \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 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %58
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %58
16: ; preds = %9
%17 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 16
store i8 0, i8* %17
%18 = call i32 @fgetc(i32* %12)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %58, label %21
21: ; preds = %16, %40
%22 = phi i32 [ %41, %40 ], [ %18, %16 ]
%23 = phi i64 [ %35, %40 ], [ 0, %16 ]
%24 = and i64 %23, 15
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 %23)
br label %28
28: ; preds = %26, %21
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%30 = add i32 %22, -32
%31 = icmp ult i32 %30, 95
%32 = trunc i32 %22 to i8
%33 = select i1 %31, i8 %32, i8 46
%34 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %24
store i8 %33, i8* %34
%35 = add i64 %23, 1
%36 = and i64 %35, 15
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %28
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %4)
br label %40
40: ; preds = %38, %28
%41 = call i32 @fgetc(i32* %12)
%42 = load i32, i32* @EOF
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %21
44: ; preds = %40
%45 = and i64 %35, 15
%46 = icmp eq i64 %45, 0
br i1 %46, label %58, label %47
47: ; preds = %44, %47
%48 = phi i64 [ %53, %47 ], [ %45, %44 ]
%49 = phi i64 [ %52, %47 ], [ %35, %44 ]
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%51 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %48
store i8 0, i8* %51
%52 = add i64 %49, 1
%53 = and i64 %52, 15
%54 = trunc i64 %52 to i4
%55 = icmp eq i4 %54, 0
br i1 %55, label %56, label %47
56: ; preds = %47
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %4)
br label %58
58: ; preds = %16, %44, %56, %14, %6
%59 = phi i32 [ 1, %6 ], [ 1, %14 ], [ 0, %56 ], [ 0, %44 ], [ 0, %16 ]
ret i32 %59
}