#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 scalar_t__ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ print_byte_hex(unsigned int);
int /*<<< orphan*/ print_str(char *);
int /*<<< orphan*/ print_u32_hex(scalar_t__);
int /*<<< orphan*/ putchar(char);
void od_hex_dump_ext(const void *data, size_t data_len, uint8_t width,
                     uint32_t offset) {
  print_u32_hex(offset);
  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)(offset + i + 1));
      }
    }
  }
}


x86 assembly (clang, -O0):
<od_hex_dump_ext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <print_u32_hex@plt>
cmpl   $0x0,-0x14(%rbp)
jne    1171 <od_hex_dump_ext+0x31>
movl   $0x10,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%rax
jae    1211 <od_hex_dump_ext+0xd1>
lea    0xe74(%rip),%rdi
call   1040 <print_str@plt>
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,4),%edi
call   1050 <print_byte_hex@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
xor    %edx,%edx
divl   -0x14(%rbp)
cmp    $0x0,%edx
je     11c8 <od_hex_dump_ext+0x88>
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jne    11fe <od_hex_dump_ext+0xbe>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
je     11f9 <od_hex_dump_ext+0xb9>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%eax
add    %rax,%rdi
add    $0x1,%rdi
call   1060 <print_u32_hex@plt>
jmp    11fe <od_hex_dump_ext+0xbe>
jmp    1203 <od_hex_dump_ext+0xc3>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1178 <od_hex_dump_ext+0x38>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<od_hex_dump_ext>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r13
mov    %rdi,%r15
mov    %rcx,(%rsp)
mov    %rcx,%rdi
call   1060 <print_u32_hex@plt>
test   %ebx,%ebx
mov    $0x10,%r14d
cmovne %ebx,%r14d
test   %r13,%r13
je     11cc <od_hex_dump_ext+0x8c>
lea    -0x1(%r13),%r12
addq   $0x1,(%rsp)
xor    %ebx,%ebx
jmp    1187 <od_hex_dump_ext+0x47>
nopl   (%rax)
mov    %ebp,%ebx
cmp    %r13,%rbx
jae    11cc <od_hex_dump_ext+0x8c>
lea    0xe72(%rip),%rdi
call   1040 <print_str@plt>
mov    (%r15,%rbx,4),%edi
call   1050 <print_byte_hex@plt>
lea    0x1(%rbx),%ebp
mov    %ebp,%eax
xor    %edx,%edx
div    %r14d
test   %edx,%edx
je     11af <od_hex_dump_ext+0x6f>
cmp    %rbx,%r12
jne    1180 <od_hex_dump_ext+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmp    %rbx,%r12
je     1180 <od_hex_dump_ext+0x40>
add    (%rsp),%rbx
mov    %rbx,%rdi
call   1060 <print_u32_hex@plt>
jmp    1180 <od_hex_dump_ext+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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