#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*/ printf(char *, ...);
void hexsummary(char *desc, const void *buf, int len) {
  int i;
  unsigned char buff[17];
  unsigned char *pc = (unsigned char *)buf;
  if (desc != NULL)
    printf("%s:\n", desc);
  for (i = 0; (i < len && i < 512); i++) {
    if ((i % 16) == 0) {
      if (i != 0)
        printf("  %s\n", buff);
      printf("  %04x ", i);
    }
    printf(" %02x", pc[i]);
    if ((pc[i] < 0x20) || (pc[i] > 0x7e))
      buff[i % 16] = '.';
    else
      buff[i % 16] = pc[i];
    buff[(i % 16) + 1] = '\0';
  }
  while ((i % 16) != 0) {
    printf("   ");
    i++;
  }
  printf("  %s\n", buff);
}


x86 assembly (clang, -O0):
<hexsummary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1148 <hexsummary+0x38>
mov    -0x8(%rbp),%rsi
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x39(%rbp)
jge    116d <hexsummary+0x5d>
cmpl   $0x200,-0x18(%rbp)
setl   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    117d <hexsummary+0x6d>
jmp    125b <hexsummary+0x14b>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11be <hexsummary+0xae>
cmpl   $0x0,-0x18(%rbp)
je     11ad <hexsummary+0x9d>
lea    -0x30(%rbp),%rsi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     1202 <hexsummary+0xf2>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jle    121a <hexsummary+0x10a>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movb   $0x2e,-0x30(%rbp,%rax,1)
jmp    1237 <hexsummary+0x127>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x18(%rbp),%eax
mov    $0x10,%esi
cltd
idiv   %esi
movslq %edx,%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
movslq %edx,%rax
movb   $0x0,-0x30(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114f <hexsummary+0x3f>
jmp    1260 <hexsummary+0x150>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1290 <hexsummary+0x180>
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1260 <hexsummary+0x150>
lea    -0x30(%rbp),%rsi
lea    0xd6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexsummary>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
test   %rdi,%rdi
je     1139 <hexsummary+0x29>
mov    %rdi,%rsi
lea    0xece(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
test   %ebx,%ebx
jle    1266 <hexsummary+0x156>
add    $0xffffffff,%ebx
cmp    $0x1ff,%ebx
mov    $0x1ff,%r15d
cmovb  %ebx,%r15d
lea    0xeb0(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl (%r14),%esi
lea    0xea4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl (%r14),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
mov    $0x2e,%ecx
cmovb  %ecx,%eax
mov    %al,(%rsp)
movb   $0x0,0x1(%rsp)
test   %r15d,%r15d
je     1232 <hexsummary+0x122>
add    $0x1,%r15d
mov    $0x1,%ebx
mov    $0x1,%r13d
sub    %r15,%r13
lea    0xe61(%rip),%rbp
jmp    11fe <hexsummary+0xee>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%r14,%rbx,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl (%r14,%rbx,1),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
mov    $0x2e,%ecx
cmovb  %ecx,%eax
mov    %al,(%rsp,%r12,1)
movb   $0x0,0x1(%rsp,%r12,1)
lea    (%rbx,%r13,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
je     122a <hexsummary+0x11a>
mov    %rbx,%r12
and    $0xf,%r12
jne    11c0 <hexsummary+0xb0>
lea    0xdf7(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xdec(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11c0 <hexsummary+0xb0>
test   $0xf,%r15b
jne    1238 <hexsummary+0x128>
jmp    1266 <hexsummary+0x156>
mov    $0x1,%r15d
add    $0x1,%r15d
lea    0xdd6(%rip),%rbx
mov    %r15d,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebp
test   $0xf,%r15b
mov    %ebp,%r15d
jne    1250 <hexsummary+0x140>
lea    0xd98(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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