#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 _hexdump_error(char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
scalar_t__ isprint(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int _hexdump_do(char *filename) {
  int ret = 0;
  FILE *fp;
  int c;
  int pos = 0;
  char buf[17] = "";
  if ((fp = fopen(filename, "r")) == NULL)
    return _hexdump_error(filename, 1);
  while ((c = fgetc(fp)) != EOF) {
    if (pos % 16 == 0)
      printf("%08x ", pos);
    else if (pos % 16 == 8)
      fputc(' ', stdout);
    printf(" %02x", (unsigned char)c);
    buf[pos % 16] = isprint(c) ? c : '.';
    if (++pos % 16 == 0)
      printf("  |%s|\n", buf);
  }
  buf[pos % 16] = '\0';
  if (pos % 16 != 0) {
    if (pos % 16 <= 8)
      fputc(' ', stdout);
    for (c = pos % 16; c < 16; c++)
      printf("%s", "   ");
    printf("  |%s|\n", buf);
  }
  if (!feof(fp))
    ret = _hexdump_error(filename, 1);
  fclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<_hexdump_do>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x28(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11ee <_hexdump_do+0x5e>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1090 <_hexdump_error@plt>
mov    %eax,-0x4(%rbp)
jmp    13b7 <_hexdump_do+0x227>
jmp    11f3 <_hexdump_do+0x63>
mov    -0x20(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2de2(%rip),%rcx
cmp    (%rcx),%eax
je     12ea <_hexdump_do+0x15a>
mov    -0x28(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1238 <_hexdump_do+0xa8>
mov    -0x28(%rbp),%esi
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1264 <_hexdump_do+0xd4>
mov    -0x28(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x8,%edx
jne    125f <_hexdump_do+0xcf>
mov    0x2d85(%rip),%rax
mov    (%rax),%esi
mov    $0x20,%edi
call   1070 <fputc@plt>
jmp    1264 <_hexdump_do+0xd4>
mov    -0x24(%rbp),%eax
movzbl %al,%esi
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%edi
call   10a0 <isprint@plt>
cmp    $0x0,%rax
je     1295 <_hexdump_do+0x105>
mov    -0x24(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    12a2 <_hexdump_do+0x112>
mov    $0x2e,%eax
mov    %eax,-0x44(%rbp)
jmp    12a2 <_hexdump_do+0x112>
mov    -0x44(%rbp),%eax
mov    %al,%cl
mov    -0x28(%rbp),%eax
mov    $0x10,%esi
cltd
idiv   %esi
movslq %edx,%rax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12e5 <_hexdump_do+0x155>
lea    -0x40(%rbp),%rsi
lea    0xd30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f3 <_hexdump_do+0x63>
mov    -0x28(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movb   $0x0,-0x40(%rbp,%rax,1)
mov    -0x28(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1385 <_hexdump_do+0x1f5>
mov    -0x28(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x8,%edx
jg     1338 <_hexdump_do+0x1a8>
mov    0x2cac(%rip),%rax
mov    (%rax),%esi
mov    $0x20,%edi
call   1070 <fputc@plt>
mov    -0x28(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
cmpl   $0x10,-0x24(%rbp)
jge    1373 <_hexdump_do+0x1e3>
lea    0xcbf(%rip),%rdi
lea    0xcbb(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1346 <_hexdump_do+0x1b6>
lea    -0x40(%rbp),%rsi
lea    0xc90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
jne    13a8 <_hexdump_do+0x218>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1090 <_hexdump_error@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_hexdump_do>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r12
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x10(%rsp)
lea    0xe5c(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     11cd <_hexdump_do+0x4d>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e28(%rip),%rcx
cmp    (%rcx),%eax
jne    11e8 <_hexdump_do+0x68>
movb   $0x0,(%rsp)
jmp    1312 <_hexdump_do+0x192>
mov    %r12,%rdi
mov    $0x1,%esi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <_hexdump_error@plt>
mov    %eax,%r14d
mov    %r12,0x20(%rsp)
mov    $0x1,%al
xor    %ebp,%ebp
jmp    121c <_hexdump_do+0x9c>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    %eax,%r14d
lea    0x1(%r13),%eax
mov    %r12,%rcx
cmp    (%r12),%r14d
je     12b0 <_hexdump_do+0x130>
mov    %rcx,%r12
mov    %eax,%r13d
mov    %ebp,%ebx
and    $0xf,%ebx
cmp    $0x8,%ebx
je     1250 <_hexdump_do+0xd0>
test   %ebx,%ebx
jne    1263 <_hexdump_do+0xe3>
lea    0xdcb(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1263 <_hexdump_do+0xe3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x2d81(%rip),%rax
mov    (%rax),%esi
mov    $0x20,%edi
call   1060 <fputc@plt>
movzbl %r14b,%esi
lea    0xd9a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,%edi
call   1090 <isprint@plt>
test   %rax,%rax
mov    $0x2e,%eax
cmove  %eax,%r14d
mov    %r14b,(%rsp,%rbx,1)
add    $0x1,%ebp
test   $0xf,%bpl
jne    1200 <_hexdump_do+0x80>
lea    0xd6d(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1200 <_hexdump_do+0x80>
and    $0xf,%ebp
movb   $0x0,(%rsp,%rbp,1)
test   %rbp,%rbp
mov    0x20(%rsp),%r12
je     1312 <_hexdump_do+0x192>
cmp    $0x8,%ebp
ja     12d9 <_hexdump_do+0x159>
mov    0x2d0b(%rip),%rax
mov    (%rax),%esi
mov    $0x20,%edi
call   1060 <fputc@plt>
movzbl %r13b,%ebx
or     $0xfffffff0,%ebx
lea    0xd2f(%rip),%r14
lea    0xd2b(%rip),%rbp
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
inc    %ebx
jne    12f0 <_hexdump_do+0x170>
lea    0xd06(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
call   1070 <feof@plt>
xor    %ebx,%ebx
test   %eax,%eax
jne    132f <_hexdump_do+0x1af>
mov    %r12,%rdi
mov    $0x1,%esi
call   1080 <_hexdump_error@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.1 = [6 x i8] c"%08x \00"
@stdout = global i32 0
@.str.2 = [6 x i8] c" %02x\00"
@.str.3 = [8 x i8] c" |%s|\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [4 x i8] c" \00"
define i32 @_hexdump_do(i8* %0) {
%2 = alloca [17 x i8]
%3 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %12, label %6
6: ; preds = %1
%7 = call i32 @fgetc(i32* %4)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
store i8 0, i8* %11
br label %59
12: ; preds = %1
%13 = tail call i32 @_hexdump_error(i8* %0, i32 1)
br label %67
14: ; preds = %6, %37
%15 = phi i32 [ %38, %37 ], [ %7, %6 ]
%16 = phi i32 [ %32, %37 ], [ 0, %6 ]
%17 = and i32 %16, 15
switch i32 %17, label %23 [
i32 0, label %18
i32 8, label %20
]
18: ; preds = %14
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %23
20: ; preds = %14
%21 = load i32, i32* @stdout
%22 = call i32 @fputc(i8 signext 32, i32 %21)
br label %23
23: ; preds = %14, %20, %18
%24 = and i32 %15, 255
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = call i64 @isprint(i32 %15)
%27 = icmp eq i64 %26, 0
%28 = trunc i32 %15 to i8
%29 = select i1 %27, i8 46, i8 %28
%30 = zext i32 %17 to i64
%31 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 %30
store i8 %29, i8* %31
%32 = add nuw nsw i32 %16, 1
%33 = and i32 %32, 15
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %23
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %3)
br label %37
37: ; preds = %35, %23
%38 = call i32 @fgetc(i32* %4)
%39 = load i32, i32* @EOF
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %14
41: ; preds = %37
%42 = and i32 %32, 15
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 %43
store i8 0, i8* %44
%45 = icmp eq i32 %42, 0
br i1 %45, label %59, label %46
46: ; preds = %41
%47 = icmp ult i32 %42, 9
br i1 %47, label %48, label %51
48: ; preds = %46
%49 = load i32, i32* @stdout
%50 = call i32 @fputc(i8 signext 32, i32 %49)
br label %51
51: ; preds = %48, %46
br label %52
52: ; preds = %51, %52
%53 = phi i32 [ %55, %52 ], [ %42, %51 ]
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%55 = add nuw nsw i32 %53, 1
%56 = icmp eq i32 %55, 16
br i1 %56, label %57, label %52
57: ; preds = %52
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %3)
br label %59
59: ; preds = %10, %57, %41
%60 = call i32 @feof(i32* %4)
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %59
%63 = call i32 @_hexdump_error(i8* %0, i32 1)
br label %64
64: ; preds = %62, %59
%65 = phi i32 [ 0, %59 ], [ %63, %62 ]
%66 = call i32 @fclose(i32* %4)
br label %67
67: ; preds = %64, %12
%68 = phi i32 [ %13, %12 ], [ %65, %64 ]
ret i32 %68
}