#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 */

/* Variables and functions */
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
scalar_t__ isprint(unsigned char const);
int /*<<< orphan*/ printf(char *, unsigned char const);
int /*<<< orphan*/ putchar(unsigned char const);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdout;
void hexdump(const void *data, size_t size) {
  const unsigned char *bytes = data;
  for (unsigned int i = 0; i < size; i += 16) {
    printf("%04X  ", i);
    unsigned int chunk_size = ((size - i) < (16) ? (size - i) : (16));
    for (unsigned int j = 0; j < chunk_size; j++) {
      printf("%02X ", bytes[i + j]);
      if (j == 7)
        putchar(' ');
    }
    for (unsigned int j = 0; j < 16 - chunk_size; j++) {
      fputs("   ", stdout);
      if (j == 8)
        putchar(' ');
    }
    putchar('|');
    for (unsigned int j = 0; j < chunk_size; j++) {
      putchar(isprint(bytes[i + j]) ? bytes[i + j] : '.');
    }
    puts("|");
  }
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%rax
jae    130a <hexdump+0x1ba>
mov    -0x1c(%rbp),%eax
lea    0xe7a(%rip),%rdi
movzbl %al,%esi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    %rcx,%rax
cmp    $0x10,%rax
jae    11b5 <hexdump+0x65>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
jmp    11c3 <hexdump+0x73>
mov    $0x10,%eax
mov    %rax,-0x38(%rbp)
jmp    11c3 <hexdump+0x73>
mov    -0x38(%rbp),%rax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jae    1220 <hexdump+0xd0>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x24(%rbp),%ecx
mov    %ecx,%ecx
lea    0xe17(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
call   1050 <printf@plt>
cmpl   $0x7,-0x24(%rbp)
jne    120d <hexdump+0xbd>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1212 <hexdump+0xc2>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d1 <hexdump+0x81>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x10,%ecx
sub    -0x20(%rbp),%ecx
cmp    %ecx,%eax
jae    1276 <hexdump+0x126>
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
lea    0xdc3(%rip),%rdi
call   1060 <fputs@plt>
cmpl   $0x8,-0x28(%rbp)
jne    1263 <hexdump+0x113>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1268 <hexdump+0x118>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1227 <hexdump+0xd7>
mov    $0x7c,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jae    12f0 <hexdump+0x1a0>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x2c(%rbp),%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%edi
call   1070 <isprint@plt>
cmp    $0x0,%rax
je     12ca <hexdump+0x17a>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x2c(%rbp),%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x3c(%rbp)
jmp    12d7 <hexdump+0x187>
mov    $0x2e,%eax
mov    %eax,-0x3c(%rbp)
jmp    12d7 <hexdump+0x187>
mov    -0x3c(%rbp),%eax
movzbl %al,%edi
call   1030 <putchar@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1287 <hexdump+0x137>
lea    0xd1a(%rip),%rdi
call   1040 <puts@plt>
mov    -0x1c(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x1c(%rbp)
jmp    116f <hexdump+0x1f>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,(%rsp)
test   %rsi,%rsi
je     12f4 <hexdump+0x1a4>
mov    %rsi,%r12
xor    %r15d,%r15d
mov    0x2e68(%rip),%rbp
lea    0xe8e(%rip),%r13
mov    %rsi,0x10(%rsp)
jmp    11b5 <hexdump+0x65>
cs nopw 0x0(%rax,%rax,1)
lea    0xe7a(%rip),%rdi
call   1040 <puts@plt>
add    $0x10,%r15d
mov    0x10(%rsp),%r12
cmp    %r12,%r15
mov    0x2e31(%rip),%rbp
jae    12f4 <hexdump+0x1a4>
sub    %r15,%r12
cmp    $0x10,%r12
mov    $0x10,%r14d
cmovb  %r12,%r14
mov    $0x10,%eax
cmovae %eax,%r12d
mov    %r15,%rcx
mov    $0x10,%r15d
sub    %r14d,%r15d
cmp    $0x2,%r15d
mov    $0x1,%eax
cmovb  %eax,%r15d
mov    %rcx,0x8(%rsp)
movzbl %cl,%esi
lea    0xe09(%rip),%rdi
call   1050 <printf@plt>
test   %r12d,%r12d
je     12c0 <hexdump+0x170>
mov    (%rsp),%rax
mov    0x8(%rsp),%rcx
lea    (%rax,%rcx,1),%rbx
xor    %ebp,%ebp
jmp    1229 <hexdump+0xd9>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r14
je     1250 <hexdump+0x100>
movzbl (%rbx,%rbp,1),%esi
lea    0xdd3(%rip),%rdi
call   1050 <printf@plt>
cmp    $0x7,%rbp
jne    1220 <hexdump+0xd0>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1220 <hexdump+0xd0>
nopl   0x0(%rax,%rax,1)
cmp    $0x10,%r12d
mov    0x2d85(%rip),%rbp
jne    12c0 <hexdump+0x170>
mov    $0x7c,%edi
call   1030 <putchar@plt>
test   %r12d,%r12d
mov    0x8(%rsp),%r15
je     1190 <hexdump+0x40>
mov    (%rsp),%rax
lea    (%rax,%r15,1),%rbp
xor    %ebx,%ebx
jmp    12aa <hexdump+0x15a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%rbp,%rbx,1),%eax
movzbl %al,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
je     1190 <hexdump+0x40>
movzbl 0x0(%rbp,%rbx,1),%edi
call   1070 <isprint@plt>
test   %rax,%rax
jne    1290 <hexdump+0x140>
mov    $0x2e,%al
jmp    1295 <hexdump+0x145>
nopl   (%rax)
xor    %ebx,%ebx
jmp    12d8 <hexdump+0x188>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebx
cmp    %ebx,%r15d
je     125d <hexdump+0x10d>
mov    0x0(%rbp),%esi
mov    %r13,%rdi
call   1060 <fputs@plt>
cmp    $0x8,%ebx
jne    12d0 <hexdump+0x180>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    12d0 <hexdump+0x180>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"%04X \00"
@.str.1 = [6 x i8] c"%02X \00"
@.str.2 = [4 x i8] c" \00"
@stdout = global i32 0
@.str.3 = [2 x i8] c"|\00"
define void @hexdump(i8* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %5
4: ; preds = %46, %2
ret void
5: ; preds = %2, %46
%6 = phi i64 [ %49, %46 ], [ 0, %2 ]
%7 = sub i64 %1, %6
%8 = call i64 @llvm.umin.i64(i64 %7, i64 16)
%9 = trunc i64 %8 to i32
%10 = sub nuw nsw i32 16, %9
%11 = call i32 @llvm.umax.i32(i32 %10, i32 1)
%12 = trunc i64 %6 to i8
%13 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %12)
%14 = sub i64 %1, %6
%15 = icmp ult i64 %14, 16
%16 = select i1 %15, i64 %14, i64 16
%17 = trunc i64 %16 to i32
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %22
19: ; preds = %31
%20 = icmp eq i32 %17, 16
br i1 %20, label %34, label %21
21: ; preds = %5, %19
br label %36
22: ; preds = %5, %31
%23 = phi i64 [ %32, %31 ], [ 0, %5 ]
%24 = add nuw nsw i64 %23, %6
%25 = getelementptr inbounds i8, i8* %0, i64 %24
%26 = load i8, i8* %25
%27 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %26)
%28 = icmp eq i64 %23, 7
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = tail call i32 @putchar(i8 zeroext 32)
br label %31
31: ; preds = %22, %29
%32 = add nuw nsw i64 %23, 1
%33 = icmp eq i64 %32, %8
br i1 %33, label %19, label %22
34: ; preds = %43, %19
%35 = tail call i32 @putchar(i8 zeroext 124)
br i1 %18, label %46, label %51
36: ; preds = %21, %43
%37 = phi i32 [ %44, %43 ], [ 0, %21 ]
%38 = load i32, i32* @stdout
%39 = tail call i32 @fputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = icmp eq i32 %37, 8
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = tail call i32 @putchar(i8 zeroext 32)
br label %43
43: ; preds = %36, %41
%44 = add nuw nsw i32 %37, 1
%45 = icmp eq i32 %44, %11
br i1 %45, label %34, label %36
46: ; preds = %60, %34
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%48 = add nuw nsw i64 %6, 16
%49 = and i64 %48, 4294967295
%50 = icmp ult i64 %49, %1
br i1 %50, label %5, label %4
51: ; preds = %34, %60
%52 = phi i64 [ %63, %60 ], [ 0, %34 ]
%53 = add nuw nsw i64 %52, %6
%54 = getelementptr inbounds i8, i8* %0, i64 %53
%55 = load i8, i8* %54
%56 = tail call i64 @isprint(i8 zeroext %55)
%57 = icmp eq i64 %56, 0
br i1 %57, label %60, label %58
58: ; preds = %51
%59 = load i8, i8* %54
br label %60
60: ; preds = %51, %58
%61 = phi i8 [ %59, %58 ], [ 46, %51 ]
%62 = tail call i32 @putchar(i8 zeroext %61)
%63 = add nuw nsw i64 %52, 1
%64 = icmp eq i64 %63, %8
br i1 %64, label %46, label %51
}