#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 hexdump(char *buf, int len) {
  int i = 0;
  char ascii[33] =
      {
          0,
      },
       *ap = ascii;
  while (i < len) {
    *ap++ = (buf[i] > 32) ? buf[i] : '.';
    *ap = '\0';
    if (!(i & 0x1F)) {
      if (!i)
        printf("%08x  ", i);
      else {
        printf("  %s\n%08x  ", ascii, i);
        ap = ascii;
      }
    } else if (!(i & 0x7))
      printf(" ");
    printf("%02x ", buf[i]);
    i++;
  }
  printf("  %s\n", ascii);
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x21,%edx
call   1040 <memset@plt>
lea    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1248 <hexdump+0x128>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jle    1183 <hexdump+0x63>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x4c(%rbp)
jmp    1190 <hexdump+0x70>
mov    $0x2e,%eax
mov    %eax,-0x4c(%rbp)
jmp    1190 <hexdump+0x70>
mov    -0x4c(%rbp),%eax
mov    %al,%cl
mov    -0x48(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x48(%rbp)
mov    %cl,(%rax)
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%eax
and    $0x1f,%eax
cmp    $0x0,%eax
jne    11fe <hexdump+0xde>
cmpl   $0x0,-0x10(%rbp)
jne    11dc <hexdump+0xbc>
mov    -0x10(%rbp),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f9 <hexdump+0xd9>
lea    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1220 <hexdump+0x100>
mov    -0x10(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
jne    121b <hexdump+0xfb>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1220 <hexdump+0x100>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114e <hexdump+0x2e>
lea    -0x40(%rbp),%rsi
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movb   $0x0,0x20(%rsp)
test   %esi,%esi
jle    117f <hexdump+0x5f>
mov    %esi,%ebx
mov    %rdi,%r14
movzbl (%rdi),%eax
cmp    $0x21,%al
mov    $0x2e,%ebp
cmovl  %ebp,%eax
mov    %al,(%rsp)
lea    0xea6(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl (%r14),%esi
lea    0xe99(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%ebx
jne    119f <hexdump+0x7f>
lea    0xe8c(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,%r12d
mov    $0x1,%ebx
lea    0x1(%rsp),%r15
lea    0xe59(%rip),%r13
jmp    11ee <hexdump+0xce>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xe39(%rip),%rdi
mov    %rsp,%r15
mov    %r15,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movsbl (%r14,%rbx,1),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
je     117f <hexdump+0x5f>
movzbl (%r14,%rbx,1),%eax
cmp    $0x21,%al
cmovl  %ebp,%eax
mov    %al,(%r15)
movb   $0x0,0x1(%r15)
test   $0x1f,%bl
je     11c0 <hexdump+0xa0>
add    $0x1,%r15
test   $0x7,%bl
jne    11d6 <hexdump+0xb6>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    11d6 <hexdump+0xb6>

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

LLVM IR (-O2):
@.str = [7 x i8] c"%08x \00"
@.str.1 = [12 x i8] c" %s\0A%08x \00"
@.str.3 = [6 x i8] c"%02x \00"
@.str.4 = [6 x i8] c" %s\0A\00"
define void @hexdump(i8* nocapture %0, i32 %1) {
%3 = alloca [33 x i8]
%4 = getelementptr inbounds [33 x i8], [33 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %43
6: ; preds = %2
%7 = zext i32 %1 to i64
%8 = load i8, i8* %0
%9 = icmp sgt i8 %8, 32
%10 = select i1 %9, i8 %8, i8 46
store i8 %10, i8* %4
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 0)
%12 = load i8, i8* %0
%13 = sext i8 %12 to i32
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = icmp eq i32 %1, 1
br i1 %15, label %43, label %16
16: ; preds = %6
%17 = getelementptr inbounds [33 x i8], [33 x i8]* %3, i64 0, i64 1
br label %18
18: ; preds = %16, %36
%19 = phi i64 [ %41, %36 ], [ 1, %16 ]
%20 = phi i8* [ %37, %36 ], [ %17, %16 ]
%21 = getelementptr inbounds i8, i8* %0, i64 %19
%22 = load i8, i8* %21
%23 = icmp sgt i8 %22, 32
%24 = select i1 %23, i8 %22, i8 46
%25 = getelementptr inbounds i8, i8* %20, i64 1
store i8 %24, i8* %20
store i8 0, i8* %25
%26 = trunc i64 %19 to i32
%27 = and i32 %26, 31
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %18
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %4, i32 %26)
br label %36
31: ; preds = %18
%32 = and i32 %26, 7
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i32 @putchar(i32 32)
br label %36
36: ; preds = %31, %34, %29
%37 = phi i8* [ %25, %31 ], [ %25, %34 ], [ %4, %29 ]
%38 = load i8, i8* %21
%39 = sext i8 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%41 = add nuw nsw i64 %19, 1
%42 = icmp eq i64 %41, %7
br i1 %42, label %43, label %18
43: ; preds = %36, %6, %2
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %4)
ret void
}