#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*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ isprint(unsigned char);
int /*<<< orphan*/ stderr;
void hexdump(const void *addr, size_t len) {
  unsigned char buff[33];
  unsigned char *pc = (unsigned char *)addr;
  if (!len) {
    return;
  }
  size_t i = 0;
  for (i = 0; i < len; i++) {
    if ((i % 32) == 0) {
      if (i != 0) {
        fprintf(stderr, "  %s\n", buff);
      }
      fprintf(stderr, "  %04zx ", i);
    }
    fprintf(stderr, " %02x", pc[i]);
    buff[i % 32] = isprint(pc[i]) ? pc[i] : '.';
    buff[(i % 32) + 1] = '\0';
  }
  while ((i % 32) != 0) {
    fprintf(stderr, "   ");
    i++;
  }
  fprintf(stderr, "  %s\n", buff);
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1148 <hexdump+0x28>
jmp    12a1 <hexdump+0x181>
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1247 <hexdump+0x127>
mov    -0x50(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
jne    11b9 <hexdump+0x99>
cmpq   $0x0,-0x50(%rbp)
je     119e <hexdump+0x7e>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rdx
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    -0x50(%rbp),%rdx
lea    0xe54(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%rax
mov    -0x50(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x48(%rbp),%rax
mov    -0x50(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     120b <hexdump+0xeb>
mov    -0x48(%rbp),%rax
mov    -0x50(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x54(%rbp)
jmp    1218 <hexdump+0xf8>
mov    $0x2e,%eax
mov    %eax,-0x54(%rbp)
jmp    1218 <hexdump+0xf8>
mov    -0x54(%rbp),%eax
mov    %al,%cl
mov    -0x50(%rbp),%rax
and    $0x1f,%rax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x50(%rbp),%rax
and    $0x1f,%rax
movb   $0x0,-0x3f(%rbp,%rax,1)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    1158 <hexdump+0x38>
jmp    124c <hexdump+0x12c>
mov    -0x50(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     1286 <hexdump+0x166>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    0xda7(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    124c <hexdump+0x12c>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rdx
lea    0xd66(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
test   %rsi,%rsi
je     127e <hexdump+0x15e>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2e9c(%rip),%r13
mov    0x0(%r13),%edi
lea    0xeb7(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%r13),%edi
movzbl (%r14),%edx
lea    0xea8(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
movzbl (%r14),%edi
call   1040 <isprint@plt>
test   %rax,%rax
je     1181 <hexdump+0x61>
mov    (%r14),%al
jmp    1183 <hexdump+0x63>
mov    $0x2e,%al
mov    %al,(%rsp)
movb   $0x0,0x1(%rsp)
cmp    $0x1,%r15
je     1225 <hexdump+0x105>
mov    $0x1,%ebx
lea    0xe6e(%rip),%r12
jmp    11c6 <hexdump+0xa6>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r14,%rbx,1),%eax
mov    %al,(%rsp,%rbp,1)
movb   $0x0,0x1(%rsp,%rbp,1)
add    $0x1,%rbx
cmp    %rbx,%r15
je     121f <hexdump+0xff>
mov    %rbx,%rbp
and    $0x1f,%rbp
jne    11f9 <hexdump+0xd9>
mov    0x0(%r13),%edi
lea    0xe26(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xe17(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%r13),%edi
movzbl (%r14,%rbx,1),%edx
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
movzbl (%r14,%rbx,1),%edi
call   1040 <isprint@plt>
test   %rax,%rax
jne    11b0 <hexdump+0x90>
mov    $0x2e,%al
jmp    11b5 <hexdump+0x95>
test   $0x1f,%r15b
je     125b <hexdump+0x13b>
add    $0x1,%r15
lea    0xde5(%rip),%rbx
mov    %r15,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%r13),%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%rbp
test   $0x1f,%r15b
mov    %rbp,%r15
jne    1240 <hexdump+0x120>
mov    0x0(%r13),%edi
lea    0xd9a(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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