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

/* Variables and functions */
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ psf_isprint(char const);
int /*<<< orphan*/ puts(char *);
void psf_hexdump(const void *ptr, int len) {
  const char *data;
  char ascii[17];
  int k, m;
  if ((data = ptr) == NULL)
    return;
  if (len <= 0)
    return;
  puts("");
  for (k = 0; k < len; k += 16) {
    memset(ascii, ' ', sizeof(ascii));
    printf("%08X: ", k);
    for (m = 0; m < 16 && k + m < len; m++) {
      printf(m == 8 ? " %02X " : "%02X ", data[k + m] & 0xFF);
      ascii[m] = psf_isprint(data[k + m]) ? data[k + m] : '.';
    };
    if (m <= 8)
      printf(" ");
    for (; m < 16; m++)
      printf("   ");
    ascii[16] = 0;
    printf(" %s\n", ascii);
  };
  puts("");
}


x86 assembly (clang, -O0):
<psf_hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1166 <psf_hexdump+0x26>
jmp    12f7 <psf_hexdump+0x1b7>
cmpl   $0x0,-0xc(%rbp)
jg     1175 <psf_hexdump+0x35>
jmp    12f7 <psf_hexdump+0x1b7>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12eb <psf_hexdump+0x1ab>
lea    -0x30(%rbp),%rdi
mov    $0x20,%esi
mov    $0x11,%edx
call   1050 <memset@plt>
mov    -0x34(%rbp),%esi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x38(%rbp)
xor    %eax,%eax
cmpl   $0x10,-0x38(%rbp)
mov    %al,-0x39(%rbp)
jge    11dd <psf_hexdump+0x9d>
mov    -0x34(%rbp),%eax
add    -0x38(%rbp),%eax
cmp    -0xc(%rbp),%eax
setl   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11ed <psf_hexdump+0xad>
jmp    1284 <psf_hexdump+0x144>
mov    -0x38(%rbp),%ecx
lea    0xe11(%rip),%rdi
lea    0xe09(%rip),%rax
cmp    $0x8,%ecx
cmove  %rax,%rdi
mov    -0x18(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%esi
and    $0xff,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <psf_isprint@plt>
cmp    $0x0,%rax
je     125c <psf_hexdump+0x11c>
mov    -0x18(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x40(%rbp)
jmp    1269 <psf_hexdump+0x129>
mov    $0x2e,%eax
mov    %eax,-0x40(%rbp)
jmp    1269 <psf_hexdump+0x129>
mov    -0x40(%rbp),%eax
mov    %al,%cl
movslq -0x38(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11bf <psf_hexdump+0x7f>
cmpl   $0x8,-0x38(%rbp)
jg     129c <psf_hexdump+0x15c>
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a1 <psf_hexdump+0x161>
cmpl   $0x10,-0x38(%rbp)
jge    12c7 <psf_hexdump+0x187>
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    12a1 <psf_hexdump+0x161>
movb   $0x0,-0x20(%rbp)
lea    -0x30(%rbp),%rsi
lea    0xd3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x34(%rbp)
jmp    1188 <psf_hexdump+0x48>
lea    0xd24(%rip),%rdi
call   1030 <puts@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psf_hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %rdi,%rdi
je     12a2 <psf_hexdump+0x162>
mov    %esi,%r14d
test   %esi,%esi
jle    12a2 <psf_hexdump+0x162>
mov    %rdi,%rbx
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14d,%r12d
lea    0x10(%rsp),%rbp
lea    0xe8a(%rip),%r13
xor    %r15d,%r15d
mov    %r14d,0xc(%rsp)
jmp    11c1 <psf_hexdump+0x81>
nopl   0x0(%rax,%rax,1)
movb   $0x0,0x20(%rsp)
lea    0xe76(%rip),%rdi
lea    0x10(%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%r15
add    $0x10,%rbx
mov    0xc(%rsp),%r14d
cmp    %r14d,%r15d
jge    1298 <psf_hexdump+0x158>
mov    %rbp,%rdi
mov    $0x20,%esi
mov    $0x11,%edx
call   1050 <memset@plt>
lea    0xe26(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x10,%ebp
xor    %r14d,%r14d
jmp    1207 <psf_hexdump+0xc7>
xchg   %ax,%ax
movzbl (%rbx,%r14,1),%eax
mov    %al,0x10(%rsp,%r14,1)
add    $0x1,%r14
add    $0xffffffff,%ebp
cmp    $0x10,%r14
je     1190 <psf_hexdump+0x50>
lea    (%r15,%r14,1),%rax
cmp    %r12,%rax
jge    1250 <psf_hexdump+0x110>
cmp    $0x8,%r14
mov    %r13,%rdi
lea    0xde9(%rip),%rax
cmove  %rax,%rdi
movzbl (%rbx,%r14,1),%esi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl (%rbx,%r14,1),%edi
call   1060 <psf_isprint@plt>
test   %rax,%rax
jne    11f0 <psf_hexdump+0xb0>
mov    $0x2e,%al
jmp    11f5 <psf_hexdump+0xb5>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x8,%r14d
ja     1270 <psf_hexdump+0x130>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1280 <psf_hexdump+0x140>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0xf,%r14d
ja     1190 <psf_hexdump+0x50>
nopw   0x0(%rax,%rax,1)
lea    0xd87(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%ebp
jne    1280 <psf_hexdump+0x140>
jmp    1190 <psf_hexdump+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [7 x i8] c"%08X: \00"
@.str.2 = [7 x i8] c" %02X \00"
@.str.3 = [6 x i8] c"%02X \00"
@.str.5 = [4 x i8] c" \00"
@.str.6 = [5 x i8] c" %s\0A\00"
define void @psf_hexdump(i8* %0, i32 %1) {
%3 = alloca [17 x i8]
%4 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %0, null
%6 = icmp slt i32 %1, 1
%7 = or i1 %5, %6
br i1 %7, label %58, label %8
8: ; preds = %2
%9 = tail call i32 @putchar(i32 10)
%10 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 16
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %8, %51
%13 = phi i64 [ 0, %8 ], [ %53, %51 ]
%14 = call i32 @memset(i8* %4, i8 signext 32, i32 17)
%15 = trunc i64 %13 to i32
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %12, %33
%18 = phi i64 [ 0, %12 ], [ %36, %33 ]
%19 = add nuw nsw i64 %18, %13
%20 = icmp slt i64 %19, %11
br i1 %20, label %21, label %38
21: ; preds = %17
%22 = icmp eq i64 %18, 8
%23 = select i1 %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%24 = getelementptr inbounds i8, i8* %0, i64 %19
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %23, i32 %26)
%28 = load i8, i8* %24
%29 = call i64 @psf_isprint(i8 signext %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %21
%32 = load i8, i8* %24
br label %33
33: ; preds = %21, %31
%34 = phi i8 [ %32, %31 ], [ 46, %21 ]
%35 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %18
store i8 %34, i8* %35
%36 = add nuw nsw i64 %18, 1
%37 = icmp eq i64 %36, 16
br i1 %37, label %51, label %17
38: ; preds = %17
%39 = trunc i64 %18 to i32
%40 = icmp ult i32 %39, 9
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 @putchar(i32 32)
br label %45
43: ; preds = %38
%44 = icmp ult i32 %39, 16
br i1 %44, label %45, label %51
45: ; preds = %41, %43
br label %46
46: ; preds = %45, %46
%47 = phi i32 [ %49, %46 ], [ %39, %45 ]
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%49 = add nuw nsw i32 %47, 1
%50 = icmp eq i32 %49, 16
br i1 %50, label %51, label %46
51: ; preds = %33, %46, %43
store i8 0, i8* %10
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%53 = add nuw i64 %13, 16
%54 = trunc i64 %53 to i32
%55 = icmp slt i32 %54, %1
br i1 %55, label %12, label %56
56: ; preds = %51
%57 = call i32 @putchar(i32 10)
br label %58
58: ; preds = %2, %56
ret void
}