#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 *info, void *addr, int len) {
  int i;
  unsigned char buff[17];
  unsigned char *pc = (unsigned char *)addr;
  if (len <= 0)
    return;
  if (info != NULL)
    printf("%s\n", info);
  for (i = 0; i < len; 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):
<hexdump>:
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)
cmpl   $0x0,-0x14(%rbp)
jg     113a <hexdump+0x2a>
jmp    128f <hexdump+0x17f>
cmpq   $0x0,-0x8(%rbp)
je     1157 <hexdump+0x47>
mov    -0x8(%rbp),%rsi
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1248 <hexdump+0x138>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ab <hexdump+0x9b>
cmpl   $0x0,-0x18(%rbp)
je     119a <hexdump+0x8a>
lea    -0x30(%rbp),%rsi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe50(%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     11ef <hexdump+0xdf>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jle    1207 <hexdump+0xf7>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movb   $0x2e,-0x30(%rbp,%rax,1)
jmp    1224 <hexdump+0x114>
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    115e <hexdump+0x4e>
jmp    124d <hexdump+0x13d>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     127d <hexdump+0x16d>
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    124d <hexdump+0x13d>
lea    -0x30(%rbp),%rsi
lea    0xd78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
test   %edx,%edx
jle    1267 <hexdump+0x147>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
test   %rdi,%rdi
je     1145 <hexdump+0x25>
call   1030 <puts@plt>
lea    0xeba(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%rbx),%esi
lea    0xeaf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%rbx),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
mov    $0x2e,%r12d
cmovb  %r12d,%eax
mov    %al,0x10(%rsp)
movb   $0x0,0x11(%rsp)
mov    $0x1,%r15d
cmp    $0x1,%ebp
je     1215 <hexdump+0xf5>
mov    %ebp,0xc(%rsp)
mov    %ebp,%r15d
mov    $0x1,%ebp
lea    0xe6a(%rip),%r14
jmp    11e0 <hexdump+0xc0>
cs nopw 0x0(%rax,%rax,1)
movzbl (%rbx,%rbp,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%rbx,%rbp,1),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
cmovb  %r12d,%eax
mov    %al,0x10(%rsp,%r13,1)
movb   $0x0,0x11(%rsp,%r13,1)
add    $0x1,%rbp
cmp    %rbp,%r15
je     120e <hexdump+0xee>
mov    %rbp,%r13
and    $0xf,%r13
jne    11b0 <hexdump+0x90>
lea    0xe10(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe03(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11b0 <hexdump+0x90>
testb  $0xf,0xc(%rsp)
je     1246 <hexdump+0x126>
add    $0x1,%r15d
lea    0xdf4(%rip),%rbx
mov    %r15d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
test   $0xf,%r15b
mov    %ebp,%r15d
jne    1230 <hexdump+0x110>
lea    0xdb3(%rip),%rdi
lea    0x10(%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

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

LLVM IR (-O2):
@.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 @hexdump(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 slt i32 %2, 1
br i1 %6, label %60, label %7
7: ; preds = %3
%8 = icmp eq i8* %0, null
br i1 %8, label %11, label %9
9: ; preds = %7
%10 = tail call i32 @puts(i8* %0)
br label %11
11: ; preds = %9, %7
%12 = zext i32 %2 to i64
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 0)
%14 = load i8, i8* %1
%15 = zext i8 %14 to i32
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = load i8, i8* %1
%18 = add i8 %17, -127
%19 = icmp ult i8 %18, -95
%20 = select i1 %19, i8 46, i8 %17
store i8 %20, i8* %5
%21 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 1
store i8 0, i8* %21
%22 = icmp eq i32 %2, 1
br i1 %22, label %26, label %28
23: ; preds = %36
%24 = and i32 %2, 15
%25 = icmp eq i32 %24, 0
br i1 %25, label %58, label %26
26: ; preds = %11, %23
%27 = phi i32 [ 1, %11 ], [ %2, %23 ]
br label %52
28: ; preds = %11, %36
%29 = phi i64 [ %50, %36 ], [ 1, %11 ]
%30 = trunc i64 %29 to i32
%31 = and i32 %30, 15
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %36
36: ; preds = %33, %28
%37 = getelementptr inbounds i8, i8* %1, i64 %29
%38 = load i8, i8* %37
%39 = zext 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 = load i8, i8* %37
%42 = add i8 %41, -127
%43 = icmp ult i8 %42, -95
%44 = zext i32 %31 to i64
%45 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 %44
%46 = select i1 %43, i8 46, i8 %41
store i8 %46, i8* %45
%47 = add nuw nsw i32 %31, 1
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 %48
store i8 0, i8* %49
%50 = add nuw nsw i64 %29, 1
%51 = icmp eq i64 %50, %12
br i1 %51, label %23, label %28
52: ; preds = %26, %52
%53 = phi i32 [ %55, %52 ], [ %27, %26 ]
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%55 = add nuw nsw i32 %53, 1
%56 = and i32 %55, 15
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %52
58: ; preds = %52, %23
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %60
60: ; preds = %3, %58
ret void
}