#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;
char *ascii(char *, int);
int /*<<< orphan*/ clear_line(char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *hex(char *, int);
int /*<<< orphan*/ printf(char *, char *, ...);
void hexdump(char *prog_name, char *filename) {
  int c = ' ';
  char *hex_offset;
  char *ascii_offset;
  FILE *ptr;
  char line[81];
  ptr = fopen(filename, "r");
  if (ferror(ptr)) {
    printf("\n\t%s: Unable to open %s\n\n", prog_name, filename);
    exit(0);
  }
  printf("\n\tHex dump of %s\n\n", filename);
  while (c != EOF) {
    clear_line(line, sizeof line);
    hex_offset = line + 1;
    ascii_offset = line + 51;
    while (ascii_offset < line + 51 + 16 && (c = fgetc(ptr)) != EOF) {
      hex_offset = hex(hex_offset, c);
      ascii_offset = ascii(ascii_offset, c);
    }
    printf("%s\n", line);
  }
  fclose(ptr);
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x20,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     11ee <hexdump+0x5e>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rsi
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%eax
mov    0x2dde(%rip),%rcx
cmp    (%rcx),%eax
je     12d5 <hexdump+0x145>
lea    -0x90(%rbp),%rdi
mov    $0x51,%esi
call   1030 <clear_line@plt>
lea    -0x90(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
lea    -0x90(%rbp),%rax
add    $0x33,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
lea    -0x90(%rbp),%rdx
add    $0x33,%rdx
add    $0x10,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x91(%rbp)
jae    1283 <hexdump+0xf3>
mov    -0x30(%rbp),%rdi
call   1080 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d70(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x91(%rbp)
mov    -0x91(%rbp),%al
test   $0x1,%al
jne    1296 <hexdump+0x106>
jmp    12bb <hexdump+0x12b>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10b0 <hex@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <ascii@plt>
mov    %rax,-0x28(%rbp)
jmp    1241 <hexdump+0xb1>
lea    -0x90(%rbp),%rsi
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1200 <hexdump+0x70>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0xe55(%rip),%rsi
mov    %rbp,%rdi
call   1090 <fopen@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    1270 <hexdump+0xe0>
lea    0xe4e(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2e09(%rip),%r15
cmpl   $0x20,(%r15)
jne    11fc <hexdump+0x6c>
mov    %r12,%rdi
call   1050 <fclose@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x43(%rsp),%r14
mov    %rsp,%rbx
jmp    1229 <hexdump+0x99>
cs nopw 0x0(%rax,%rax,1)
lea    0xe18(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
cmp    (%r15),%ebp
je     11e5 <hexdump+0x55>
mov    %rbx,%rdi
mov    $0x51,%esi
call   1030 <clear_line@plt>
lea    0x33(%rsp),%rbx
lea    0x1(%rsp),%r13
mov    %r12,%rdi
call   1080 <fgetc@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
je     1210 <hexdump+0x80>
mov    %r13,%rdi
mov    %ebp,%esi
call   10b0 <hex@plt>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <ascii@plt>
mov    %rax,%rbx
cmp    %r14,%rax
jb     1240 <hexdump+0xb0>
jmp    1210 <hexdump+0x80>
lea    0xd8b(%rip),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"\0A\09%s: Unable to open %s\0A\0A\00"
@.str.2 = [19 x i8] c"\0A\09Hex dump of %s\0A\0A\00"
@EOF = global i32 0
@.str.3 = [4 x i8] c"%s\0A\00"
define void @hexdump(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca [81 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 32, i32* %5
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %8
%12 = load i32*, i32** %8
%13 = call i64 @ferror(i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = load i8*, i8** %4
%18 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %17)
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %2
%21 = load i8*, i8** %4
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %54, %20
%24 = load i32, i32* %5
%25 = load i32, i32* @EOF
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %57
27: ; preds = %23
%28 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 0
%29 = call i32 @clear_line(i8* %28, i32 81)
%30 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 0
%31 = getelementptr inbounds i8, i8* %30, i64 1
store i8* %31, i8** %6
%32 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 0
%33 = getelementptr inbounds i8, i8* %32, i64 51
store i8* %33, i8** %7
br label %34
34: ; preds = %47, %27
%35 = load i8*, i8** %7
%36 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 0
%37 = getelementptr inbounds i8, i8* %36, i64 51
%38 = getelementptr inbounds i8, i8* %37, i64 16
%39 = icmp ult i8* %35, %38
br i1 %39, label %40, label %45
40: ; preds = %34
%41 = load i32*, i32** %8
%42 = call i32 @fgetc(i32* %41)
store i32 %42, i32* %5
%43 = load i32, i32* @EOF
%44 = icmp ne i32 %42, %43
br label %45
45: ; preds = %40, %34
%46 = phi i1 [ false, %34 ], [ %44, %40 ]
br i1 %46, label %47, label %54
47: ; preds = %45
%48 = load i8*, i8** %6
%49 = load i32, i32* %5
%50 = call i8* @hex(i8* %48, i32 %49)
store i8* %50, i8** %6
%51 = load i8*, i8** %7
%52 = load i32, i32* %5
%53 = call i8* @ascii(i8* %51, i32 %52)
store i8* %53, i8** %7
br label %34
54: ; preds = %45
%55 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 0
%56 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %55)
br label %23
57: ; preds = %23
%58 = load i32*, i32** %8
%59 = call i32 @fclose(i32* %58)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"\0A\09%s: Unable to open %s\0A\0A\00"
@.str.2 = [19 x i8] c"\0A\09Hex dump of %s\0A\0A\00"
@EOF = global i32 0
@.str.3 = [4 x i8] c"%s\0A\00"
define void @hexdump(i8* %0, i8* %1) {
%3 = alloca [81 x i8]
%4 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = tail call i64 @ferror(i32* %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %2
%12 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %13, 32
br i1 %14, label %35, label %15
15: ; preds = %11
%16 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 1
%17 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 51
%18 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 67
br label %19
19: ; preds = %15, %31
%20 = call i32 @clear_line(i8* %4, i32 81)
br label %21
21: ; preds = %19, %27
%22 = phi i8* [ %17, %19 ], [ %29, %27 ]
%23 = phi i8* [ %16, %19 ], [ %28, %27 ]
%24 = call i32 @fgetc(i32* %5)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %31, label %27
27: ; preds = %21
%28 = call i8* @hex(i8* %23, i32 %24)
%29 = call i8* @ascii(i8* %22, i32 %24)
%30 = icmp ult i8* %29, %18
br i1 %30, label %21, label %31
31: ; preds = %27, %21
%32 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %24, %33
br i1 %34, label %35, label %19
35: ; preds = %31, %11
%36 = call i32 @fclose(i32* %5)
ret void
}