#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*/ printf(char *, ...);
void debug_dump_hex(const unsigned char *buf, int len) {
  unsigned int line_count = 0;
  unsigned int line, last_col;
  unsigned int i;
  line_count = len >> 4;
  for (line = 0; line < line_count; line++) {
    printf("%04xh: ", line);
    for (i = 0; i < 16; i++) {
      printf("%02X ", *buf);
      buf++;
    }
    printf("\n");
  }
  last_col = len & 0x0f;
  if (last_col) {
    printf("%04xh: ", line);
    for (i = 0; i < last_col; i++) {
      printf("%02X ", *buf);
      buf++;
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<debug_dump_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    11af <debug_dump_hex+0x9f>
mov    -0x14(%rbp),%esi
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
jae    1193 <debug_dump_hex+0x83>
mov    -0x8(%rbp),%rax
movzbl (%rax),%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115a <debug_dump_hex+0x4a>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1136 <debug_dump_hex+0x26>
mov    -0xc(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1223 <debug_dump_hex+0x113>
mov    -0x14(%rbp),%esi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    1215 <debug_dump_hex+0x105>
mov    -0x8(%rbp),%rax
movzbl (%rax),%esi
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11da <debug_dump_hex+0xca>
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debug_dump_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
xor    %r12d,%r12d
cmp    $0x10,%esi
jb     1265 <debug_dump_hex+0x145>
mov    %r14d,%eax
sar    $0x4,%eax
cmp    $0x2,%eax
mov    $0x1,%r12d
cmovae %eax,%r12d
lea    0xea9(%rip),%r15
lea    0xeaa(%rip),%r13
xor    %ebp,%ebp
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%rbx),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x1(%rbx),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x2(%rbx),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x3(%rbx),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x4(%rbx),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x5(%rbx),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x6(%rbx),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x7(%rbx),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x8(%rbx),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x9(%rbx),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0xa(%rbx),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0xb(%rbx),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0xc(%rbx),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0xd(%rbx),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0xe(%rbx),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0xf(%rbx),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%rbx
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
cmp    %ebp,%r12d
jne    1160 <debug_dump_hex+0x40>
test   $0xf,%r14b
je     12bf <debug_dump_hex+0x19f>
lea    0xd8e(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
and    $0xf,%r14d
lea    0xd81(%rip),%r15
xor    %ebp,%ebp
nopl   0x0(%rax)
movzbl (%rbx,%rbp,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %ebp,%r14d
jne    1290 <debug_dump_hex+0x170>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [8 x i8] c"%04xh: \00"
@.str.1 = [6 x i8] c"%02X \00"
define void @debug_dump_hex(i8* nocapture %0, i32 %1) {
%3 = icmp ult i32 %1, 16
br i1 %3, label %78, label %4
4: ; preds = %2
%5 = ashr i32 %1, 4
%6 = call i32 @llvm.umax.i32(i32 %5, i32 1)
br label %7
7: ; preds = %4, %7
%8 = phi i8* [ %74, %7 ], [ %0, %4 ]
%9 = phi i32 [ %76, %7 ], [ 0, %4 ]
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i8, i8* %8
%12 = zext i8 %11 to i32
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds i8, i8* %8, i64 1
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds i8, i8* %8, i64 2
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds i8, i8* %8, i64 3
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds i8, i8* %8, i64 4
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds i8, i8* %8, i64 5
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds i8, i8* %8, i64 6
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = getelementptr inbounds i8, i8* %8, i64 7
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = getelementptr inbounds i8, i8* %8, i64 8
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %44)
%46 = getelementptr inbounds i8, i8* %8, i64 9
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%50 = getelementptr inbounds i8, i8* %8, i64 10
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %52)
%54 = getelementptr inbounds i8, i8* %8, i64 11
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %56)
%58 = getelementptr inbounds i8, i8* %8, i64 12
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %60)
%62 = getelementptr inbounds i8, i8* %8, i64 13
%63 = load i8, i8* %62
%64 = zext i8 %63 to i32
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %64)
%66 = getelementptr inbounds i8, i8* %8, i64 14
%67 = load i8, i8* %66
%68 = zext i8 %67 to i32
%69 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %68)
%70 = getelementptr inbounds i8, i8* %8, i64 15
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %72)
%74 = getelementptr inbounds i8, i8* %8, i64 16
%75 = tail call i32 @putchar(i32 10)
%76 = add nuw i32 %9, 1
%77 = icmp eq i32 %76, %6
br i1 %77, label %78, label %7
78: ; preds = %7, %2
%79 = phi i32 [ 0, %2 ], [ %6, %7 ]
%80 = phi i8* [ %0, %2 ], [ %74, %7 ]
%81 = and i32 %1, 15
%82 = icmp eq i32 %81, 0
br i1 %82, label %96, label %83
83: ; preds = %78
%84 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %79)
br label %85
85: ; preds = %83, %85
%86 = phi i32 [ %92, %85 ], [ 0, %83 ]
%87 = phi i8* [ %91, %85 ], [ %80, %83 ]
%88 = load i8, i8* %87
%89 = zext i8 %88 to i32
%90 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %89)
%91 = getelementptr inbounds i8, i8* %87, i64 1
%92 = add nuw nsw i32 %86, 1
%93 = icmp eq i32 %92, %81
br i1 %93, label %94, label %85
94: ; preds = %85
%95 = tail call i32 @putchar(i32 10)
br label %96
96: ; preds = %94, %78
ret void
}