#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 /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  if (argc != 2)
    return 0;
  FILE *fin = fopen(argv[1], "rb");
  int count = 0;
  while (!feof(fin)) {
    unsigned char b;
    if (fread(&b, 1, 1, fin) != 1)
      break;
    printf("0x%02x, ", b);
    if (++count % 16 == 0)
      printf("\n");
  }
  fclose(fin);
}


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)
je     117c <main+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    1223 <main+0xd3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe75(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b9 <main+0x69>
jmp    121a <main+0xca>
mov    -0x18(%rbp),%rcx
lea    -0x1d(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x1,%eax
je     11db <main+0x8b>
jmp    121a <main+0xca>
movzbl -0x1d(%rbp),%esi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1215 <main+0xc5>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    119b <main+0x4b>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
cmp    $0x2,%edi
jne    119d <main+0x3d>
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
lea    0xe89(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11a0 <main+0x40>
mov    %rbx,%rdi
call   1050 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
xor    %eax,%eax
ret
mov    $0x1,%ebp
lea    0x7(%rsp),%r14
lea    0xe52(%rip),%r15
jmp    11cf <main+0x6f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1070 <feof@plt>
add    $0x1,%ebp
test   %eax,%eax
jne    118b <main+0x2b>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    118b <main+0x2b>
movzbl 0x7(%rsp),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   $0xf,%bpl
jne    11c0 <main+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11c0 <main+0x60>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [9 x i8] c"0x%02x, \00"
@.str.2 = [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 i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %41
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %6
store i32 0, i32* %7
br label %17
17: ; preds = %37, %12
%18 = load i32*, i32** %6
%19 = call i32 @feof(i32* %18)
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
br i1 %21, label %22, label %38
22: ; preds = %17
%23 = load i32*, i32** %6
%24 = call i32 @fread(i8* %8, i32 1, i32 1, i32* %23)
%25 = icmp ne i32 %24, 1
br i1 %25, label %26, label %27
26: ; preds = %22
br label %38
27: ; preds = %22
%28 = load i8, i8* %8
%29 = zext i8 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
%33 = srem i32 %32, 16
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %27
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %27
br label %17
38: ; preds = %26, %17
%39 = load i32*, i32** %6
%40 = call i32 @fclose(i32* %39)
br label %41
41: ; preds = %38, %11
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [9 x i8] c"0x%02x, \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp eq i32 %0, 2
br i1 %4, label %5, label %30
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @feof(i32* %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %5, %25
%12 = phi i32 [ %20, %25 ], [ 0, %5 ]
%13 = call i32 @fread(i8* %3, i32 1, i32 1, i32* %8)
%14 = icmp eq i32 %13, 1
br i1 %14, label %16, label %15
15: ; preds = %11
br label %28
16: ; preds = %11
%17 = load i8, i8* %3
%18 = zext i8 %17 to i32
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = add nuw nsw i32 %12, 1
%21 = and i32 %20, 15
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = tail call i32 @putchar(i32 10)
br label %25
25: ; preds = %16, %23
%26 = tail call i32 @feof(i32* %8)
%27 = icmp eq i32 %26, 0
br i1 %27, label %11, label %28
28: ; preds = %25, %5, %15
%29 = tail call i32 @fclose(i32* %8)
br label %30
30: ; preds = %2, %28
ret i32 0
}