#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 *, ...);
int /*<<< orphan*/ putchar(int);
void hexdump(char *data, int addr, int len) {
  int i, n;
  while (len) {
    n = (len > 16) ? 16 : len;
    printf("%04x  ", addr);
    addr += n;
    len -= n;
    for (i = 0; i < 16; i++) {
      if (i >= n)
        printf("   ");
      else
        printf(" %02x", data[i] & 0xff);
    }
    printf("   *");
    while (n--) {
      if ((i = *data++ & 0x7f) < ' ' || i == 0x7f)
        i = '.';
      putchar(i);
    }
    printf("*\n");
  }
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     125b <hexdump+0x13b>
cmpl   $0x10,-0x10(%rbp)
jle    1153 <hexdump+0x33>
mov    $0x10,%eax
mov    %eax,-0x1c(%rbp)
jmp    1159 <hexdump+0x39>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    11e7 <hexdump+0xc7>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     11b4 <hexdump+0x94>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d4 <hexdump+0xb4>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
and    $0xff,%esi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d9 <hexdump+0xb9>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118b <hexdump+0x6b>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
je     1248 <hexdump+0x128>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
and    $0x7f,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x20,%eax
jl     1234 <hexdump+0x114>
cmpl   $0x7f,-0x14(%rbp)
jne    123b <hexdump+0x11b>
movl   $0x2e,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <putchar@plt>
jmp    11f5 <hexdump+0xd5>
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1132 <hexdump+0x12>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
je     121f <hexdump+0xef>
mov    %esi,%ebx
mov    %rdi,%rbp
mov    $0x2e,%r15d
lea    0xeb2(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0x10,%edx
mov    $0x10,%r14d
mov    %edx,0x4(%rsp)
cmovl  %edx,%r14d
lea    0xe88(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    %r14d,%ebx
mov    %ebx,(%rsp)
movslq %r14d,%r12
xor    %ebx,%ebx
jmp    11ad <hexdump+0x7d>
xchg   %ax,%ax
movzbl 0x0(%rbp,%rbx,1),%esi
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    $0x10,%rbx
je     11c0 <hexdump+0x90>
cmp    %r12,%rbx
jl     1190 <hexdump+0x60>
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11a3 <hexdump+0x73>
xchg   %ax,%ax
lea    0xe4a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
and    $0x7f,%eax
cmp    $0x7f,%al
mov    %eax,%edi
cmove  %r15d,%edi
cmp    $0x20,%al
cmovb  %r15d,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
jne    11e0 <hexdump+0xb0>
lea    0xe0a(%rip),%rdi
call   1040 <puts@plt>
mov    0x4(%rsp),%edx
sub    %r14d,%edx
mov    (%rsp),%ebx
jne    1160 <hexdump+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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