#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(int);
int /*<<< orphan*/ stderr;
void hexdump(void *mem, unsigned int len) {
  char *mem_ch = (char *)mem;
  unsigned int i, j;
  for (i = 0; i < len + ((len % 8) ? (8 - len % 8) : 0); i++) {
    if (i % 8 == 0) {
      fprintf(stderr, "0x%06x: ", i);
    }
    if (i < len) {
      fprintf(stderr, "%02x ", 0xFF & ((char *)mem)[i]);
    } else {
      fprintf(stderr, "   ");
    }
    if (i % 8 == (8 - 1)) {
      for (j = i - (8 - 1); j <= i; j++) {
        if (j >= len) {
          fprintf(stderr, " ");
        } else if (isprint((int)mem_ch[j])) {
          fprintf(stderr, "%c", 0xFF & ((char *)mem)[j]);
        } else {
          fprintf(stderr, ".");
        }
      }
      fprintf(stderr, "\n");
    }
  }
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
je     116e <hexdump+0x4e>
mov    -0xc(%rbp),%ecx
and    $0x7,%ecx
mov    $0x8,%eax
sub    %ecx,%eax
mov    %eax,-0x2c(%rbp)
jmp    1178 <hexdump+0x58>
xor    %eax,%eax
mov    %eax,-0x2c(%rbp)
jmp    1178 <hexdump+0x58>
mov    -0x28(%rbp),%eax
mov    -0x24(%rbp),%ecx
mov    -0x2c(%rbp),%edx
add    %edx,%ecx
cmp    %ecx,%eax
jae    12f0 <hexdump+0x1d0>
mov    -0x1c(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
jne    11b4 <hexdump+0x94>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xe53(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11ed <hexdump+0xcd>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%edx
and    $0xff,%edx
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1204 <hexdump+0xe4>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
and    $0x7,%eax
cmp    $0x7,%eax
jne    12dd <hexdump+0x1bd>
mov    -0x1c(%rbp),%eax
sub    $0x7,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
ja     12c6 <hexdump+0x1a6>
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jb     1250 <hexdump+0x130>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12b3 <hexdump+0x193>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     1297 <hexdump+0x177>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
movsbl (%rax,%rcx,1),%edx
and    $0xff,%edx
lea    0xd88(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12ae <hexdump+0x18e>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
lea    0xd6f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12b3 <hexdump+0x193>
jmp    12b8 <hexdump+0x198>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    121c <hexdump+0xfc>
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
lea    0xd42(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12e2 <hexdump+0x1c2>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113e <hexdump+0x1e>
add    $0x30,%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    %esi,%ecx
and    $0x7,%ecx
mov    $0x8,%eax
sub    %ecx,%eax
test   %ecx,%ecx
cmove  %ecx,%eax
add    %esi,%eax
je     1268 <hexdump+0x148>
mov    %esi,%ebx
mov    %rdi,%r14
mov    %esi,%r15d
mov    %eax,%eax
mov    %rax,0x10(%rsp)
mov    0x2e83(%rip),%r12
xor    %r13d,%r13d
mov    %r15,0x8(%rsp)
jmp    1196 <hexdump+0x76>
nopw   0x0(%rax,%rax,1)
mov    (%r12),%edi
lea    0xe9d(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x8(%rsp),%r15
add    $0x1,%r13
cmp    0x10(%rsp),%r13
je     1268 <hexdump+0x148>
mov    %r13d,%ebp
and    $0x7,%ebp
jne    11b3 <hexdump+0x93>
mov    (%r12),%edi
lea    0xe57(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r12),%edi
cmp    %r15,%r13
jae    11e0 <hexdump+0xc0>
movzbl (%r14,%r13,1),%edx
lea    0xe41(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    $0x7,%ebp
jne    1187 <hexdump+0x67>
jmp    11f3 <hexdump+0xd3>
cs nopw 0x0(%rax,%rax,1)
lea    0xe28(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    $0x7,%ebp
jne    1187 <hexdump+0x67>
cmp    $0x7,%r13
jb     1170 <hexdump+0x50>
lea    -0x7(%r13),%r15d
jmp    122f <hexdump+0x10f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12),%edi
lea    0xdf6(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%r15d
cmp    %r15,%r13
jb     1170 <hexdump+0x50>
cmp    %ebx,%r15d
jae    1210 <hexdump+0xf0>
mov    %r15d,%ebp
movsbl (%r14,%rbp,1),%edi
call   1040 <isprint@plt>
mov    (%r12),%edi
test   %rax,%rax
je     125f <hexdump+0x13f>
movzbl (%r14,%rbp,1),%edx
lea    0xdbd(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1222 <hexdump+0x102>
lea    0xdb0(%rip),%rsi
jmp    121b <hexdump+0xfb>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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