#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(unsigned char *buffer, unsigned long index, unsigned long width) {
  unsigned long i;
  for (i = 0; i < index; i++) {
    printf("%02x ", buffer[i]);
  }
  for (unsigned long spacer = index; spacer < width; spacer++)
    printf("   ");
  printf(": ");
  for (i = 0; i < index; i++) {
    if (buffer[i] < 32)
      printf(".");
    else
      printf("%c", buffer[i]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1165 <hexdump+0x55>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112c <hexdump+0x1c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    119a <hexdump+0x8a>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    116d <hexdump+0x5d>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1216 <hexdump+0x106>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jge    11e6 <hexdump+0xd6>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1200 <hexdump+0xf0>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1205 <hexdump+0xf5>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11b0 <hexdump+0xa0>
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
test   %rsi,%rsi
je     1158 <hexdump+0x38>
lea    0xec3(%rip),%r12
xor    %ebp,%ebp
nop
movzbl (%r14,%rbp,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1140 <hexdump+0x20>
cmp    %rbx,%r15
jae    1180 <hexdump+0x60>
sub    %r15,%rbx
lea    0xe9f(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffffffffffff,%rbx
jne    1170 <hexdump+0x50>
lea    0xe83(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r15,%r15
je     11bb <hexdump+0x9b>
xor    %ebx,%ebx
mov    $0x2e,%ebp
nopw   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%eax
cmp    $0x20,%al
cmovb  %ebp,%eax
movzbl %al,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11a0 <hexdump+0x80>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

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