#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*/ putch(unsigned char);
void hexdump(void *xbuf, int len) {
  char *buf = xbuf;
  int addr, i, j;
  for (addr = 0; addr < len; addr += 20) {
    printf("%08x: ", addr);
    for (i = 0; i < 20; i += 4) {
      for (j = 0; j < 4; j++) {
        if (addr + i + j >= len) {
          printf("..");
        } else {
          printf("%02x", (unsigned char)buf[addr + i + j]);
        }
      }
      printf(" ");
    }
    printf(" |");
    for (i = 0; i < 20; i++) {
      if (addr + i > len) {
        putch('.');
      } else {
        putch((unsigned char)buf[addr + i + j]);
      }
    }
    printf("|\n");
  }
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1278 <hexdump+0x158>
mov    -0x1c(%rbp),%esi
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0x14,-0x20(%rbp)
jge    11f3 <hexdump+0xd3>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    11d7 <hexdump+0xb7>
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
add    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     11a2 <hexdump+0x82>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c4 <hexdump+0xa4>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
add    -0x24(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c9 <hexdump+0xa9>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1173 <hexdump+0x53>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x20(%rbp)
jmp    1162 <hexdump+0x42>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0x14,-0x20(%rbp)
jge    125c <hexdump+0x13c>
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1230 <hexdump+0x110>
mov    $0x2e,%edi
call   1040 <putch@plt>
jmp    1249 <hexdump+0x129>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
add    -0x24(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edi
call   1040 <putch@plt>
jmp    124e <hexdump+0x12e>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1208 <hexdump+0xe8>
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x14,%eax
mov    %eax,-0x1c(%rbp)
jmp    113e <hexdump+0x1e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    12f8 <hexdump+0x1b8>
mov    %esi,%ebx
mov    %rdi,%r14
lea    0x3(%rdi),%r12
add    $0x4,%r14
lea    0xea3(%rip),%rbp
lea    0xe99(%rip),%r15
xor    %r13d,%r13d
jmp    11a8 <hexdump+0x68>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xe89(%rip),%rdi
call   1040 <puts@plt>
add    $0x14,%r13
add    $0x14,%r12
add    $0x14,%r14
cmp    %ebx,%r13d
lea    0xe68(%rip),%rbp
jge    12f8 <hexdump+0x1b8>
mov    %r14,(%rsp)
lea    0xe4d(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xfffffffffffffffc,%r14
jmp    11f8 <hexdump+0xb8>
cs nopw 0x0(%rax,%rax,1)
movzbl 0x4(%r12,%r14,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0x4,%r14
cmp    $0x10,%r14
jae    12b0 <hexdump+0x170>
lea    (%r14,%r13,1),%eax
add    $0x4,%eax
cmp    %ebx,%eax
jge    1220 <hexdump+0xe0>
movzbl 0x1(%r12,%r14,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    122a <hexdump+0xea>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    (%r14,%r13,1),%eax
add    $0x5,%eax
cmp    %ebx,%eax
jge    1250 <hexdump+0x110>
movzbl 0x2(%r12,%r14,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    125a <hexdump+0x11a>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    (%r14,%r13,1),%eax
add    $0x6,%eax
cmp    %ebx,%eax
jge    1280 <hexdump+0x140>
movzbl 0x3(%r12,%r14,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    128a <hexdump+0x14a>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    (%r14,%r13,1),%eax
add    $0x7,%eax
cmp    %ebx,%eax
jl     11d0 <hexdump+0x90>
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11e0 <hexdump+0xa0>
nopl   0x0(%rax,%rax,1)
lea    0xd58(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %ebp,%ebp
mov    (%rsp),%r14
jmp    12e6 <hexdump+0x1a6>
cs nopw 0x0(%rax,%rax,1)
movzbl %al,%edi
call   1060 <putch@plt>
add    $0x1,%rbp
cmp    $0x14,%rbp
je     1180 <hexdump+0x40>
lea    0x0(%r13,%rbp,1),%ecx
mov    $0x2e,%al
cmp    %ebx,%ecx
jg     12d0 <hexdump+0x190>
movzbl (%r14,%rbp,1),%eax
jmp    12d0 <hexdump+0x190>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"%08x: \00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [5 x i8] c"%02x\00"
@.str.4 = [3 x i8] c" |\00"
@str = [2 x i8] c"|\00"
define void @hexdump(i8* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %78
4: ; preds = %2, %73
%5 = phi i64 [ %75, %73 ], [ 0, %2 ]
%6 = trunc i64 %5 to i32
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %8
8: ; preds = %4, %53
%9 = phi i64 [ 0, %4 ], [ %55, %53 ]
%10 = add nuw nsw i64 %9, %5
%11 = trunc i64 %10 to i32
%12 = icmp slt i32 %11, %1
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %20
15: ; preds = %8
%16 = getelementptr inbounds i8, i8* %0, i64 %10
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %13, %15
%21 = or i64 %10, 1
%22 = trunc i64 %21 to i32
%23 = icmp slt i32 %22, %1
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %31
26: ; preds = %20
%27 = getelementptr inbounds i8, i8* %0, i64 %21
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %26, %24
%32 = or i64 %10, 2
%33 = trunc i64 %32 to i32
%34 = icmp slt i32 %33, %1
br i1 %34, label %37, label %35
35: ; preds = %31
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %42
37: ; preds = %31
%38 = getelementptr inbounds i8, i8* %0, i64 %32
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %37, %35
%43 = or i64 %10, 3
%44 = trunc i64 %43 to i32
%45 = icmp slt i32 %44, %1
br i1 %45, label %48, label %46
46: ; preds = %42
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %53
48: ; preds = %42
%49 = getelementptr inbounds i8, i8* %0, i64 %43
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %48, %46
%54 = tail call i32 @putchar(i32 32)
%55 = add nuw nsw i64 %9, 4
%56 = icmp ult i64 %9, 16
br i1 %56, label %8, label %57
57: ; preds = %53
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %59
59: ; preds = %57, %68
%60 = phi i64 [ 0, %57 ], [ %71, %68 ]
%61 = add nuw nsw i64 %60, %5
%62 = trunc i64 %61 to i32
%63 = icmp sgt i32 %62, %1
br i1 %63, label %68, label %64
64: ; preds = %59
%65 = add nuw nsw i64 %61, 4
%66 = getelementptr inbounds i8, i8* %0, i64 %65
%67 = load i8, i8* %66
br label %68
68: ; preds = %59, %64
%69 = phi i8 [ %67, %64 ], [ 46, %59 ]
%70 = tail call i32 @putch(i8 zeroext %69)
%71 = add nuw nsw i64 %60, 1
%72 = icmp eq i64 %71, 20
br i1 %72, label %73, label %59
73: ; preds = %68
%74 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%75 = add nuw i64 %5, 20
%76 = trunc i64 %75 to i32
%77 = icmp slt i32 %76, %1
br i1 %77, label %4, label %78
78: ; preds = %73, %2
ret void
}