#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void hex_dump(FILE *f, void *p, size_t count) {
  uint8_t *q = p;
  int i, j;
  for (i = 0; i < count; i += 16) {
    fprintf(f, "%04x:", i);
    for (j = i; j < (i + 16); j++)
      if (j < count)
        fprintf(f, " %02x", q[j]);
      else
        fprintf(f, "   ");
    fprintf(f, "\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    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11e2 <hex_dump+0xd2>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xeb1(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    $0x10,%ecx
cmp    %ecx,%eax
jge    11c2 <hex_dump+0xb2>
movslq -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    119d <hex_dump+0x8d>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11af <hex_dump+0x9f>
mov    -0x8(%rbp),%rdi
lea    0xe64(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11b4 <hex_dump+0xa4>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    115c <hex_dump+0x4c>
mov    -0x8(%rbp),%rdi
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x24(%rbp)
jmp    1133 <hex_dump+0x23>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     11df <hex_dump+0xaf>
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeb8(%rip),%rbp
xor    %r12d,%r12d
jmp    117a <hex_dump+0x4a>
nopl   0x0(%rax)
add    $0x10,%r12
mov    $0xa,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
add    $0x40,%r14
cmp    %r15,%r12
jae    11df <hex_dump+0xaf>
mov    %rbx,%rdi
lea    0xe7c(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %r13d,%r13d
jmp    11bf <hex_dump+0x8f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %rbx,%rcx
call   1050 <fwrite@plt>
add    $0x1,%r13
cmp    $0x10,%r13
je     1160 <hex_dump+0x30>
lea    (%r12,%r13,1),%rax
cmp    %r15,%rax
jae    11a0 <hex_dump+0x70>
mov    (%r14,%r13,4),%edx
mov    %rbx,%rdi
lea    0xe30(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11b5 <hex_dump+0x85>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%04x:\00"
@.str.1 = [6 x i8] c" %02x\00"
@.str.2 = [4 x i8] c" \00"
define void @hex_dump(i32* nocapture %0, i8* nocapture %1, i64 %2) {
%4 = bitcast i8* %1 to i32*
%5 = icmp eq i64 %2, 0
br i1 %5, label %28, label %6
6: ; preds = %3, %23
%7 = phi i64 [ %27, %23 ], [ 16, %3 ]
%8 = phi i64 [ %24, %23 ], [ 0, %3 ]
%9 = trunc i64 %8 to i32
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %6, %20
%12 = phi i64 [ %8, %6 ], [ %21, %20 ]
%13 = icmp ult i64 %12, %2
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = getelementptr inbounds i32, i32* %4, i64 %12
%16 = load i32, i32* %15
%17 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %20
18: ; preds = %11
%19 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 3, i64 1, i32* %0)
br label %20
20: ; preds = %14, %18
%21 = add nuw i64 %12, 1
%22 = icmp eq i64 %21, %7
br i1 %22, label %23, label %11
23: ; preds = %20
%24 = add nuw i64 %8, 16
%25 = tail call i32 @fputc(i32 10, i32* %0)
%26 = icmp ult i64 %24, %2
%27 = add i64 %7, 16
br i1 %26, label %6, label %28
28: ; preds = %23, %3
ret void
}