#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 */
typedef int uint8_t;
typedef size_t uint16_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void hex_dump(const char *def, uint8_t *data, uint16_t len, uint16_t br) {
  uint16_t i;
  printf("\n%s:\n", def);
  for (i = 0; i < len; ++i) {
    if (i && (i % br == 0))
      printf("\n");
    printf("0x%02X ", data[i]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<hex_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a9 <hex_dump+0x99>
cmpq   $0x0,-0x28(%rbp)
je     117f <hex_dump+0x6f>
mov    -0x28(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x20(%rbp)
cmp    $0x0,%rdx
jne    117f <hex_dump+0x6f>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1142 <hex_dump+0x32>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_dump>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rsi
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14,%r14
je     115f <hex_dump+0x3f>
mov    (%r15),%esi
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%r14
jne    1172 <hex_dump+0x52>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>
mov    $0x1,%ebx
lea    0xe88(%rip),%r13
jmp    1197 <hex_dump+0x77>
mov    (%r15,%rbx,4),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
je     115f <hex_dump+0x3f>
mov    %rbx,%rax
or     %r12,%rax
shr    $0x20,%rax
je     11c0 <hex_dump+0xa0>
mov    %rbx,%rax
xor    %edx,%edx
div    %r12
test   %rdx,%rdx
jne    1180 <hex_dump+0x60>
jmp    11cc <hex_dump+0xac>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%eax
xor    %edx,%edx
div    %r12d
test   %rdx,%rdx
jne    1180 <hex_dump+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1180 <hex_dump+0x60>

LLVM IR (-O0):
@.str = [6 x i8] c"\0A%s:\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [8 x i8] c"0x%02X \00"
define void @hex_dump(i8* %0, i32* %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i8* %0, i8** %5
store i32* %1, i32** %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%10 = load i8*, i8** %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %10)
store i64 0, i64* %9
br label %12
12: ; preds = %32, %4
%13 = load i64, i64* %9
%14 = load i64, i64* %7
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %35
16: ; preds = %12
%17 = load i64, i64* %9
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i64, i64* %9
%21 = load i64, i64* %8
%22 = urem i64 %20, %21
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %19, %16
%27 = load i32*, i32** %6
%28 = load i64, i64* %9
%29 = getelementptr inbounds i32, i32* %27, i64 %28
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %26
%33 = load i64, i64* %9
%34 = add i64 %33, 1
store i64 %34, i64* %9
br label %12
35: ; preds = %12
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"\0A%s:\0A\00"
@.str.2 = [8 x i8] c"0x%02X \00"
define void @hex_dump(i8* %0, i32* nocapture %1, i64 %2, i64 %3) {
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = icmp eq i64 %2, 0
br i1 %6, label %23, label %7
7: ; preds = %4
%8 = load i32, i32* %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = icmp eq i64 %2, 1
br i1 %10, label %23, label %11
11: ; preds = %7, %17
%12 = phi i64 [ %21, %17 ], [ 1, %7 ]
%13 = urem i64 %12, %3
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 @putchar(i32 10)
br label %17
17: ; preds = %15, %11
%18 = getelementptr inbounds i32, i32* %1, i64 %12
%19 = load i32, i32* %18
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = add nuw i64 %12, 1
%22 = icmp eq i64 %21, %2
br i1 %22, label %23, label %11
23: ; preds = %17, %7, %4
%24 = tail call i32 @putchar(i32 10)
ret void
}