#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 */
scalar_t__ isprint(unsigned char const);
int /*<<< orphan*/ printf(char *, unsigned char const, ...);
void dump_bytes(const void *base, unsigned size) {
  const unsigned char *p = base;
  unsigned to_dump;
  unsigned x;
  if (size < 16)
    to_dump = size;
  else
    to_dump = 16;
  for (x = 0; x < to_dump; x++)
    printf(" %02x(%c)", p[x], isprint(p[x]) ? p[x] : '.');
  if (size != to_dump) {
    printf("... (%d more)", size - to_dump);
  } else {
    switch (size) {
    case 2:
      printf(" = 0x%x", *(unsigned short *)base);
      break;
    case 4:
      printf(" = 0x%x", *(unsigned int *)base);
      break;
    case 8:
      printf(" = 0x%lx", *(unsigned long *)base);
      break;
    case 16:
      printf(" = 0x%lx:0x%lx", ((unsigned long *)base)[0],
             ((unsigned long *)base)[1]);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<dump_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x10,-0xc(%rbp)
jae    114c <dump_bytes+0x2c>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1153 <dump_bytes+0x33>
movl   $0x10,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    11d2 <dump_bytes+0xb2>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
movzbl (%rax,%rcx,1),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     11a0 <dump_bytes+0x80>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x28(%rbp)
jmp    11ad <dump_bytes+0x8d>
mov    $0x2e,%eax
mov    %eax,-0x28(%rbp)
jmp    11ad <dump_bytes+0x8d>
mov    -0x21(%rbp),%al
mov    -0x28(%rbp),%edx
lea    0xe82(%rip),%rdi
movzbl %al,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115a <dump_bytes+0x3a>
mov    -0xc(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11fa <dump_bytes+0xda>
mov    -0xc(%rbp),%eax
sub    -0x1c(%rbp),%eax
lea    0xe5b(%rip),%rdi
movzbl %al,%esi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129e <dump_bytes+0x17e>
mov    -0xc(%rbp),%eax
add    $0xfffffffe,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0xe,%eax
ja     1299 <dump_bytes+0x179>
mov    -0x30(%rbp),%rax
lea    0xde6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rax
mov    (%rax),%ax
lea    0xe23(%rip),%rdi
movzbl %al,%esi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1299 <dump_bytes+0x179>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
lea    0xe07(%rip),%rdi
movzbl %al,%esi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1299 <dump_bytes+0x179>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
lea    0xdf2(%rip),%rdi
movzbl %al,%esi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1299 <dump_bytes+0x179>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
mov    0x8(%rcx),%rdx
lea    0xdd6(%rip),%rdi
movzbl %al,%esi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129e <dump_bytes+0x17e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_bytes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
cmp    $0x10,%esi
mov    $0x10,%eax
cmovb  %esi,%eax
mov    %eax,0x4(%rsp)
test   %eax,%eax
je     1192 <dump_bytes+0x72>
mov    0x4(%rsp),%r13d
lea    0xed0(%rip),%r15
xor    %r12d,%r12d
jmp    117a <dump_bytes+0x5a>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rbx,%r12,1),%edx
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%r12
cmp    %r12,%r13
je     1192 <dump_bytes+0x72>
movzbl (%rbx,%r12,1),%ebp
mov    %ebp,%edi
call   1040 <isprint@plt>
test   %rax,%rax
jne    1160 <dump_bytes+0x40>
mov    $0x2e,%edx
jmp    1165 <dump_bytes+0x45>
cmp    $0x11,%r14d
jae    11c1 <dump_bytes+0xa1>
add    $0xfffffffe,%r14d
ror    %r14d
cmp    $0x7,%r14d
ja     11e6 <dump_bytes+0xc6>
lea    0xe54(%rip),%rax
movslq (%rax,%r14,4),%rcx
add    %rax,%rcx
jmp    *%rcx
movzbl (%rbx),%esi
lea    0xe79(%rip),%rdi
jmp    11d1 <dump_bytes+0xb1>
sub    0x4(%rsp),%r14d
movzbl %r14b,%esi
lea    0xe59(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movzbl (%rbx),%esi
lea    0xe41(%rip),%rdi
jmp    11d1 <dump_bytes+0xb1>
movzbl (%rbx),%esi
mov    0x8(%rbx),%rdx
lea    0xe3a(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [10 x i8] c" %02x(%c)\00"
@.str.1 = [14 x i8] c"... (%d more)\00"
@.str.2 = [8 x i8] c" = 0x%x\00"
@.str.3 = [9 x i8] c" = 0x%lx\00"
@.str.4 = [15 x i8] c" = 0x%lx:0x%lx\00"
define void @dump_bytes(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
store i8* %8, i8** %5
%9 = load i32, i32* %4
%10 = icmp ult i32 %9, 16
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load i32, i32* %4
store i32 %12, i32* %6
br label %14
13: ; preds = %2
store i32 16, i32* %6
br label %14
14: ; preds = %13, %11
store i32 0, i32* %7
br label %15
15: ; preds = %43, %14
%16 = load i32, i32* %7
%17 = load i32, i32* %6
%18 = icmp ult i32 %16, %17
br i1 %18, label %19, label %46
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = load i32, i32* %7
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = load i8*, i8** %5
%26 = load i32, i32* %7
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = call i64 @isprint(i8 zeroext %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %19
%33 = load i8*, i8** %5
%34 = load i32, i32* %7
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
br label %40
39: ; preds = %19
br label %40
40: ; preds = %39, %32
%41 = phi i32 [ %38, %32 ], [ 46, %39 ]
%42 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8 zeroext %24, i32 %41)
br label %43
43: ; preds = %40
%44 = load i32, i32* %7
%45 = add i32 %44, 1
store i32 %45, i32* %7
br label %15
46: ; preds = %15
%47 = load i32, i32* %4
%48 = load i32, i32* %6
%49 = icmp ne i32 %47, %48
br i1 %49, label %50, label %56
50: ; preds = %46
%51 = load i32, i32* %4
%52 = load i32, i32* %6
%53 = sub i32 %51, %52
%54 = trunc i32 %53 to i8
%55 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %54)
br label %88
56: ; preds = %46
%57 = load i32, i32* %4
switch i32 %57, label %87 [
i32 2, label %58
i32 4, label %64
i32 8, label %70
i32 16, label %76
]
58: ; preds = %56
%59 = load i8*, i8** %3
%60 = bitcast i8* %59 to i16*
%61 = load i16, i16* %60
%62 = trunc i16 %61 to i8
%63 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %62)
br label %87
64: ; preds = %56
%65 = load i8*, i8** %3
%66 = bitcast i8* %65 to i32*
%67 = load i32, i32* %66
%68 = trunc i32 %67 to i8
%69 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %68)
br label %87
70: ; preds = %56
%71 = load i8*, i8** %3
%72 = bitcast i8* %71 to i64*
%73 = load i64, i64* %72
%74 = trunc i64 %73 to i8
%75 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %74)
br label %87
76: ; preds = %56
%77 = load i8*, i8** %3
%78 = bitcast i8* %77 to i64*
%79 = getelementptr inbounds i64, i64* %78, i64 0
%80 = load i64, i64* %79
%81 = trunc i64 %80 to i8
%82 = load i8*, i8** %3
%83 = bitcast i8* %82 to i64*
%84 = getelementptr inbounds i64, i64* %83, i64 1
%85 = load i64, i64* %84
%86 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %81, i64 %85)
br label %87
87: ; preds = %56, %76, %70, %64, %58
br label %88
88: ; preds = %87, %50
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c" %02x(%c)\00"
@.str.1 = [14 x i8] c"... (%d more)\00"
@.str.2 = [8 x i8] c" = 0x%x\00"
@.str.3 = [9 x i8] c" = 0x%lx\00"
@.str.4 = [15 x i8] c" = 0x%lx:0x%lx\00"
define void @dump_bytes(i8* nocapture %0, i32 %1) {
%3 = icmp ult i32 %1, 16
%4 = select i1 %3, i32 %1, i32 16
%5 = icmp eq i32 %4, 0
br i1 %5, label %22, label %6
6: ; preds = %2
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %17
%9 = phi i64 [ 0, %6 ], [ %20, %17 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i64 @isprint(i8 zeroext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %8
%15 = load i8, i8* %10
%16 = zext i8 %15 to i32
br label %17
17: ; preds = %8, %14
%18 = phi i32 [ %16, %14 ], [ 46, %8 ]
%19 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8 zeroext %11, i32 %18)
%20 = add nuw nsw i64 %9, 1
%21 = icmp eq i64 %20, %7
br i1 %21, label %22, label %8
22: ; preds = %17, %2
%23 = icmp ult i32 %1, 17
br i1 %23, label %28, label %24
24: ; preds = %22
%25 = sub i32 %1, %4
%26 = trunc i32 %25 to i8
%27 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %26)
br label %54
28: ; preds = %22
%29 = add nsw i32 %1, -2
%30 = tail call i32 @llvm.fshl.i32(i32 %29, i32 %29, i32 31)
switch i32 %30, label %54 [
i32 0, label %31
i32 1, label %36
i32 3, label %41
i32 7, label %46
]
31: ; preds = %28
%32 = bitcast i8* %0 to i16*
%33 = load i16, i16* %32
%34 = trunc i16 %33 to i8
%35 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %34)
br label %54
36: ; preds = %28
%37 = bitcast i8* %0 to i32*
%38 = load i32, i32* %37
%39 = trunc i32 %38 to i8
%40 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %39)
br label %54
41: ; preds = %28
%42 = bitcast i8* %0 to i64*
%43 = load i64, i64* %42
%44 = trunc i64 %43 to i8
%45 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %44)
br label %54
46: ; preds = %28
%47 = bitcast i8* %0 to i64*
%48 = load i64, i64* %47
%49 = trunc i64 %48 to i8
%50 = getelementptr inbounds i8, i8* %0, i64 8
%51 = bitcast i8* %50 to i64*
%52 = load i64, i64* %51
%53 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %49, i64 %52)
br label %54
54: ; preds = %31, %36, %41, %46, %28, %24
ret void
}