#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*/ out(char *, char const *, ...);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char const);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strncat(char *, unsigned char const *, int);
void hexdump(const char *label, const unsigned char *data,
             const unsigned int length) {
  unsigned int i = 0;
  char line[16 * 3 + 1];
  char hrline[16 * 3 + 1];
  char hex[4];
  out("%s (%i bytes):\n", label, length);
  line[0] = '\0';
  hrline[0] = '\0';
  for (i = 1; i <= length; i++) {
    sprintf(hex, "%.2X ", data[i - 1]);
    strcat(line, hex);
    if (data[i - 1] >= 33 && data[i - 1] <= 126) {
      strncat(hrline, data + (i - 1), 1);
    } else {
      strcat(hrline, ".");
    }
    if (i % 16 == 0) {
      out("%s   %s\n", line, hrline);
      line[0] = '\0';
      hrline[0] = '\0';
    }
  }
  out("%s   %s\n", line, hrline);
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1060 <out@plt>
movb   $0x0,-0x50(%rbp)
movb   $0x0,-0x90(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
ja     1273 <hexdump+0x133>
lea    -0x94(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
lea    0xe66(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1050 <sprintf@plt>
lea    -0x50(%rbp),%rdi
lea    -0x94(%rbp),%rsi
call   1040 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%eax
cmp    $0x21,%eax
jl     121a <hexdump+0xda>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jg     121a <hexdump+0xda>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,%eax
add    %rax,%rsi
mov    $0x1,%edx
call   1030 <strncat@plt>
jmp    122d <hexdump+0xed>
lea    -0x90(%rbp),%rdi
lea    0xdee(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x18(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    1260 <hexdump+0x120>
lea    -0x50(%rbp),%rsi
lea    -0x90(%rbp),%rdx
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1060 <out@plt>
movb   $0x0,-0x50(%rbp)
movb   $0x0,-0x90(%rbp)
jmp    1265 <hexdump+0x125>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1184 <hexdump+0x44>
lea    -0x50(%rbp),%rsi
lea    -0x90(%rbp),%rdx
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1060 <out@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%rsi
lea    0xe9f(%rip),%rdi
xor    %eax,%eax
call   1060 <out@plt>
movb   $0x0,0x10(%rsp)
movb   $0x0,0x50(%rsp)
test   %r15d,%r15d
je     122a <hexdump+0xea>
mov    $0x1,%r12d
lea    0xc(%rsp),%rbp
lea    0x50(%rsp),%r13
jmp    119d <hexdump+0x5d>
nopl   (%rax)
add    $0x1,%r12d
cmp    %r15d,%r12d
ja     122a <hexdump+0xea>
lea    -0x1(%r12),%r14d
movzbl (%rbx,%r14,1),%edx
mov    %rbp,%rdi
lea    0xe5f(%rip),%rsi
call   1050 <sprintf@plt>
lea    0x10(%rsp),%rdi
mov    %rbp,%rsi
call   1040 <strcat@plt>
movzbl (%rbx,%r14,1),%eax
add    $0xdf,%al
cmp    $0x5d,%al
ja     11f0 <hexdump+0xb0>
add    %rbx,%r14
mov    %r13,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <strncat@plt>
test   $0xf,%r12b
jne    1190 <hexdump+0x50>
jmp    1205 <hexdump+0xc5>
nopl   0x0(%rax)
mov    %r13,%rdi
lea    0xe1c(%rip),%rsi
call   1040 <strcat@plt>
test   $0xf,%r12b
jne    1190 <hexdump+0x50>
lea    0xe0c(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <out@plt>
movb   $0x0,0x10(%rsp)
movb   $0x0,0x50(%rsp)
jmp    1190 <hexdump+0x50>
lea    0xde7(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x50(%rsp),%rdx
xor    %eax,%eax
call   1060 <out@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"%s (%i bytes):\0A\00"
@.str.1 = [6 x i8] c"%.2X \00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [9 x i8] c"%s %s\0A\00"
define void @hexdump(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [49 x i8]
%9 = alloca [49 x i8]
%10 = alloca [4 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
%11 = load i8*, i8** %4
%12 = load i32, i32* %6
%13 = call i32 (i8*, i8*, ...) @out(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %12)
%14 = getelementptr inbounds [49 x i8], [49 x i8]* %8, i64 0, i64 0
store i8 0, i8* %14
%15 = getelementptr inbounds [49 x i8], [49 x i8]* %9, i64 0, i64 0
store i8 0, i8* %15
store i32 1, i32* %7
br label %16
16: ; preds = %71, %3
%17 = load i32, i32* %7
%18 = load i32, i32* %6
%19 = icmp ule i32 %17, %18
br i1 %19, label %20, label %74
20: ; preds = %16
%21 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%22 = load i8*, i8** %5
%23 = load i32, i32* %7
%24 = sub i32 %23, 1
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = load i8, i8* %26
%28 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %27)
%29 = getelementptr inbounds [49 x i8], [49 x i8]* %8, i64 0, i64 0
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%31 = call i32 @strcat(i8* %29, i8* %30)
%32 = load i8*, i8** %5
%33 = load i32, i32* %7
%34 = sub i32 %33, 1
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = icmp sge i32 %38, 33
br i1 %39, label %40, label %57
40: ; preds = %20
%41 = load i8*, i8** %5
%42 = load i32, i32* %7
%43 = sub i32 %42, 1
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = icmp sle i32 %47, 126
br i1 %48, label %49, label %57
49: ; preds = %40
%50 = getelementptr inbounds [49 x i8], [49 x i8]* %9, i64 0, i64 0
%51 = load i8*, i8** %5
%52 = load i32, i32* %7
%53 = sub i32 %52, 1
%54 = zext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %51, i64 %54
%56 = call i32 @strncat(i8* %50, i8* %55, i32 1)
br label %60
57: ; preds = %40, %20
%58 = getelementptr inbounds [49 x i8], [49 x i8]* %9, i64 0, i64 0
%59 = call i32 @strcat(i8* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %60
60: ; preds = %57, %49
%61 = load i32, i32* %7
%62 = urem i32 %61, 16
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %70
64: ; preds = %60
%65 = getelementptr inbounds [49 x i8], [49 x i8]* %8, i64 0, i64 0
%66 = getelementptr inbounds [49 x i8], [49 x i8]* %9, i64 0, i64 0
%67 = call i32 (i8*, i8*, ...) @out(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %65, i8* %66)
%68 = getelementptr inbounds [49 x i8], [49 x i8]* %8, i64 0, i64 0
store i8 0, i8* %68
%69 = getelementptr inbounds [49 x i8], [49 x i8]* %9, i64 0, i64 0
store i8 0, i8* %69
br label %70
70: ; preds = %64, %60
br label %71
71: ; preds = %70
%72 = load i32, i32* %7
%73 = add i32 %72, 1
store i32 %73, i32* %7
br label %16
74: ; preds = %16
%75 = getelementptr inbounds [49 x i8], [49 x i8]* %8, i64 0, i64 0
%76 = getelementptr inbounds [49 x i8], [49 x i8]* %9, i64 0, i64 0
%77 = call i32 (i8*, i8*, ...) @out(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %75, i8* %76)
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"%s (%i bytes):\0A\00"
@.str.1 = [6 x i8] c"%.2X \00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [9 x i8] c"%s %s\0A\00"
define void @hexdump(i8* %0, i8* %1, i32 %2) {
%4 = alloca [49 x i8]
%5 = alloca [49 x i8]
%6 = alloca [4 x i8]
%7 = getelementptr inbounds [49 x i8], [49 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [49 x i8], [49 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%10 = tail call i32 (i8*, i8*, ...) @out(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %2)
store i8 0, i8* %7
store i8 0, i8* %8
%11 = icmp eq i32 %2, 0
br i1 %11, label %35, label %12
12: ; preds = %3, %32
%13 = phi i32 [ %33, %32 ], [ 1, %3 ]
%14 = add i32 %13, -1
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %1, i64 %15
%17 = load i8, i8* %16
%18 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %17)
%19 = call i32 @strcat(i8* %7, i8* %9)
%20 = load i8, i8* %16
%21 = add i8 %20, -33
%22 = icmp ult i8 %21, 94
br i1 %22, label %23, label %25
23: ; preds = %12
%24 = call i32 @strncat(i8* %8, i8* %16, i32 1)
br label %27
25: ; preds = %12
%26 = call i32 @strcat(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %23
%28 = and i32 %13, 15
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 (i8*, i8*, ...) @out(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %7, i8* %8)
store i8 0, i8* %7
store i8 0, i8* %8
br label %32
32: ; preds = %27, %30
%33 = add i32 %13, 1
%34 = icmp ugt i32 %33, %2
br i1 %34, label %35, label %12
35: ; preds = %32, %3
%36 = call i32 (i8*, i8*, ...) @out(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %7, i8* %8)
ret void
}