#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*/ assert(int);
int /*<<< orphan*/ bytes_to_hex(void const *, size_t, char **);
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ printf(char *, char const *, char *);
void hexdump(const char *prefix, const size_t column_len, const void *value,
             size_t len) {
  assert(prefix != NULL);
  assert(column_len > 0);
  int row_count = (len / column_len) + 1;
  int i;
  size_t slen = column_len * 3;
  char *s = malloc(slen * sizeof(char));
  for (i = 0; i < row_count; ++i) {
    memset(s, 0, slen);
    bytes_to_hex(value, len, (char **)&s);
    printf("%s %s\n", prefix, s);
  }
  free(s);
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
add    $0x1,%rax
mov    %eax,-0x24(%rbp)
imul   $0x3,-0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
shl    $0x0,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    121e <hexdump+0xbe>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1070 <bytes_to_hex@plt>
mov    -0x8(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xdf5(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11d0 <hexdump+0x70>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1060 <assert@plt>
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1060 <assert@plt>
mov    %r12,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     11ac <hexdump+0x4c>
mov    %r12,%rax
xor    %edx,%edx
div    %rbx
mov    %rax,%r13
jmp    11b6 <hexdump+0x56>
mov    %r12d,%eax
xor    %edx,%edx
div    %ebx
mov    %eax,%r13d
lea    (%rbx,%rbx,2),%rbx
mov    %rbx,%rdi
call   1080 <malloc@plt>
mov    %rax,%rdi
mov    %rax,(%rsp)
cmp    $0x7ffffffe,%r13d
ja     1228 <hexdump+0xc8>
add    $0x1,%r13d
cmp    $0x2,%r13d
mov    $0x1,%r14d
cmovge %r13d,%r14d
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
xor    %esi,%esi
mov    %rbx,%rdx
call   1050 <memset@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %rsp,%rdx
call   1070 <bytes_to_hex@plt>
mov    (%rsp),%rdx
lea    0xded(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
add    $0x1,%r13d
mov    (%rsp),%rdi
cmp    %r14d,%r13d
jne    11f0 <hexdump+0x90>
call   1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%s %s\0A\00"
define void @hexdump(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i64, i64* %6
%18 = icmp ugt i64 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i64, i64* %8
%22 = load i64, i64* %6
%23 = udiv i64 %21, %22
%24 = add i64 %23, 1
%25 = trunc i64 %24 to i32
store i32 %25, i32* %9
%26 = load i64, i64* %6
%27 = mul i64 %26, 3
store i64 %27, i64* %11
%28 = load i64, i64* %11
%29 = mul i64 %28, 1
%30 = call i8* @malloc(i64 %29)
store i8* %30, i8** %12
store i32 0, i32* %10
br label %31
31: ; preds = %45, %4
%32 = load i32, i32* %10
%33 = load i32, i32* %9
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %48
35: ; preds = %31
%36 = load i8*, i8** %12
%37 = load i64, i64* %11
%38 = call i32 @memset(i8* %36, i32 0, i64 %37)
%39 = load i8*, i8** %7
%40 = load i64, i64* %8
%41 = call i32 @bytes_to_hex(i8* %39, i64 %40, i8** %12)
%42 = load i8*, i8** %5
%43 = load i8*, i8** %12
%44 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %42, i8* %43)
br label %45
45: ; preds = %35
%46 = load i32, i32* %10
%47 = add nsw i32 %46, 1
store i32 %47, i32* %10
br label %31
48: ; preds = %31
%49 = load i8*, i8** %12
%50 = call i32 @free(i8* %49)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s %s\0A\00"
define void @hexdump(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = icmp ne i8* %0, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = icmp ne i64 %1, 0
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = udiv i64 %3, %1
%13 = trunc i64 %12 to i32
%14 = mul i64 %1, 3
%15 = bitcast i8** %5 to i8*
%16 = tail call i8* @malloc(i64 %14)
store i8* %16, i8** %5
%17 = icmp ult i32 %13, 2147483647
br i1 %17, label %18, label %31
18: ; preds = %4
%19 = add i32 %13, 1
%20 = call i32 @llvm.smax.i32(i32 %19, i32 1)
br label %21
21: ; preds = %21, %18
%22 = phi i8* [ %16, %18 ], [ %30, %21 ]
%23 = phi i32 [ 0, %18 ], [ %28, %21 ]
%24 = call i32 @memset(i8* %22, i32 0, i64 %14)
%25 = call i32 @bytes_to_hex(i8* %2, i64 %3, i8** %5)
%26 = load i8*, i8** %5
%27 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %26)
%28 = add nuw nsw i32 %23, 1
%29 = icmp eq i32 %28, %20
%30 = load i8*, i8** %5
br i1 %29, label %31, label %21
31: ; preds = %21, %4
%32 = phi i8* [ %16, %4 ], [ %30, %21 ]
%33 = call i32 @free(i8* %32)
ret void
}