#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 unsigned int uint8_t;
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ print_byte_hex(unsigned int);
int /*<<< orphan*/ print_str(char *);
int /*<<< orphan*/ print_u32_hex(int /*<<< orphan*/);
int /*<<< orphan*/ putchar(char);
void od_hex_dump(const void *data, size_t data_len, uint8_t width) {
  print_str("00000000");
  if (width == 0) {
    width = (16);
  }
  for (unsigned int i = 0; i < data_len; i++) {
    print_str("  ");
    print_byte_hex(((uint8_t *)data)[i]);
    if ((((i + 1) % width) == 0) || i == (data_len - 1)) {
      putchar('\n');
      if (i != (data_len - 1)) {
        print_u32_hex((uint32_t)(i + 1));
      }
    }
  }
}


x86 assembly (clang, -O0):
<od_hex_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    0xea6(%rip),%rdi
call   1040 <print_str@plt>
cmpl   $0x0,-0x14(%rbp)
jne    1170 <od_hex_dump+0x30>
movl   $0x10,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%rax
jae    1208 <od_hex_dump+0xc8>
lea    0xe7e(%rip),%rdi
call   1040 <print_str@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    (%rax,%rcx,4),%edi
call   1050 <print_byte_hex@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
xor    %edx,%edx
divl   -0x14(%rbp)
cmp    $0x0,%edx
je     11c7 <od_hex_dump+0x87>
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jne    11f5 <od_hex_dump+0xb5>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
je     11f0 <od_hex_dump+0xb0>
mov    -0x18(%rbp),%edi
add    $0x1,%edi
call   1060 <print_u32_hex@plt>
jmp    11f5 <od_hex_dump+0xb5>
jmp    11fa <od_hex_dump+0xba>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1177 <od_hex_dump+0x37>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<od_hex_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r12
mov    %rdi,%r14
lea    0xea6(%rip),%rdi
call   1040 <print_str@plt>
test   %ebp,%ebp
mov    $0x10,%r13d
cmovne %ebp,%r13d
test   %r12,%r12
je     11c9 <od_hex_dump+0x89>
lea    -0x1(%r12),%rbx
xor    %r15d,%r15d
jmp    1188 <od_hex_dump+0x48>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%r15d
cmp    %r12,%r15
jae    11c9 <od_hex_dump+0x89>
lea    0xe7a(%rip),%rdi
call   1040 <print_str@plt>
mov    (%r14,%r15,4),%edi
call   1050 <print_byte_hex@plt>
lea    0x1(%r15),%ebp
mov    %ebp,%eax
xor    %edx,%edx
div    %r13d
test   %edx,%edx
je     11b1 <od_hex_dump+0x71>
cmp    %r15,%rbx
jne    1180 <od_hex_dump+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmp    %r15,%rbx
je     1180 <od_hex_dump+0x40>
mov    %ebp,%edi
call   1060 <print_u32_hex@plt>
jmp    1180 <od_hex_dump+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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