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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int const);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void hex_dump(const uint8_t *buf, unsigned int n_bytes) {
  const unsigned int mod = 16;
  unsigned int i;
  for (i = 0; i < n_bytes; ++i) {
    fprintf(stderr, "%02x ", buf[i]);
    if ((mod - 1) == (i % mod)) {
      if (1) {
        unsigned int j;
        fputc(' ', stderr);
        for (j = 0; j < mod; ++j) {
          int c = buf[i - mod + 1 + j];
          if ((c & 0x7F) < 0x20)
            c = '.';
          fputc(c, stderr);
        }
      }
      fputc('\n', stderr);
    }
  }
  if ((mod - 1) != (n_bytes % mod))
    fputc('\n', stderr);
}


x86 assembly (clang, -O0):
<hex_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x10,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1215 <hex_dump+0xf5>
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,4),%edx
lea    0xe9d(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%ecx
and    $0xf,%ecx
mov    $0xf,%eax
cmp    %ecx,%eax
jne    1202 <hex_dump+0xe2>
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
mov    $0x20,%edi
call   1030 <fputc@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x10,-0x18(%rbp)
jae    11ef <hex_dump+0xcf>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x10,%ecx
add    $0x1,%ecx
add    -0x18(%rbp),%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x7f,%eax
cmp    $0x20,%eax
jge    11cd <hex_dump+0xad>
movl   $0x2e,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e09(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1030 <fputc@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1195 <hex_dump+0x75>
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1030 <fputc@plt>
jmp    1207 <hex_dump+0xe7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113d <hex_dump+0x1d>
mov    -0xc(%rbp),%ecx
and    $0xf,%ecx
mov    $0xf,%eax
cmp    %ecx,%eax
je     123b <hex_dump+0x11b>
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1030 <fputc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %esi,%esi
je     11ef <hex_dump+0xcf>
mov    %rdi,%rbx
mov    %esi,0xc(%rsp)
mov    %esi,%r12d
mov    $0xfffffff1,%ebp
xor    %r13d,%r13d
mov    0x2e91(%rip),%r14
mov    $0x2e,%r15d
mov    %r12,0x10(%rsp)
jmp    116d <hex_dump+0x4d>
nopl   0x0(%rax)
add    $0x1,%r13
add    $0x1,%rbp
cmp    %r12,%r13
je     11d6 <hex_dump+0xb6>
mov    (%r14),%edi
mov    (%rbx,%r13,4),%edx
lea    0xe85(%rip),%rsi
call   1040 <fprintf@plt>
mov    %r13d,%eax
not    %eax
test   $0xf,%al
jne    1160 <hex_dump+0x40>
mov    (%r14),%esi
mov    $0x20,%edi
call   1030 <fputc@plt>
xor    %r12d,%r12d
nopl   0x0(%rax)
lea    (%r12,%rbp,1),%eax
mov    (%rbx,%rax,4),%eax
test   $0x60,%al
cmove  %r15d,%eax
mov    (%r14),%esi
movsbl %al,%edi
call   1030 <fputc@plt>
add    $0x1,%r12
cmp    $0x10,%r12
jne    11a0 <hex_dump+0x80>
mov    (%r14),%esi
mov    $0xa,%edi
call   1030 <fputc@plt>
mov    0x10(%rsp),%r12
jmp    1160 <hex_dump+0x40>
mov    0xc(%rsp),%eax
not    %eax
test   $0xf,%al
jne    11ef <hex_dump+0xcf>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fputc@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [6 x i8] c"%02x \00"
define void @hex_dump(i32* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %41, label %4
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %35
%7 = phi i64 [ 0, %4 ], [ %36, %35 ]
%8 = load i32, i32* @stderr
%9 = getelementptr inbounds i32, i32* %0, i64 %7
%10 = load i32, i32* %9
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = and i64 %7, 15
%13 = icmp eq i64 %12, 15
br i1 %13, label %14, label %35
14: ; preds = %6
%15 = load i32, i32* @stderr
%16 = tail call i32 @fputc(i8 signext 32, i32 %15)
%17 = add nuw i64 %7, 4294967281
br label %18
18: ; preds = %14, %18
%19 = phi i64 [ 0, %14 ], [ %30, %18 ]
%20 = add i64 %17, %19
%21 = and i64 %20, 4294967295
%22 = getelementptr inbounds i32, i32* %0, i64 %21
%23 = load i32, i32* %22
%24 = and i32 %23, 96
%25 = icmp eq i32 %24, 0
%26 = trunc i32 %23 to i8
%27 = select i1 %25, i8 46, i8 %26
%28 = load i32, i32* @stderr
%29 = tail call i32 @fputc(i8 signext %27, i32 %28)
%30 = add nuw nsw i64 %19, 1
%31 = icmp eq i64 %30, 16
br i1 %31, label %32, label %18
32: ; preds = %18
%33 = load i32, i32* @stderr
%34 = tail call i32 @fputc(i8 signext 10, i32 %33)
br label %35
35: ; preds = %6, %32
%36 = add nuw nsw i64 %7, 1
%37 = icmp eq i64 %36, %5
br i1 %37, label %38, label %6
38: ; preds = %35
%39 = and i32 %1, 15
%40 = icmp eq i32 %39, 15
br i1 %40, label %44, label %41
41: ; preds = %2, %38
%42 = load i32, i32* @stderr
%43 = tail call i32 @fputc(i8 signext 10, i32 %42)
br label %44
44: ; preds = %41, %38
ret void
}