#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;
  unsigned 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)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%rax
jae    11df <hex_dump+0xcf>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xeb2(%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
jae    11bf <hex_dump+0xaf>
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%rax
jae    119a <hex_dump+0x8a>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    (%rax,%rcx,4),%edx
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11ac <hex_dump+0x9c>
mov    -0x8(%rbp),%rdi
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11b1 <hex_dump+0xa1>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    115b <hex_dump+0x4b>
mov    -0x8(%rbp),%rdi
lea    0xe46(%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     11fe <hex_dump+0xce>
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeac(%rip),%rbp
xor    %r12d,%r12d
jmp    1180 <hex_dump+0x50>
nopl   0x0(%rax)
lea    0xe99(%rip),%rbp
mov    $0xa,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
mov    0x4(%rsp),%eax
mov    %eax,%r12d
cmp    %r15,%r13
jae    11fe <hex_dump+0xce>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0x10(%r12),%eax
cmp    $0xfffffff0,%r12d
mov    %eax,0x4(%rsp)
jne    11b0 <hex_dump+0x80>
xor    %r13d,%r13d
jmp    1167 <hex_dump+0x37>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12d,%ebp
mov    %eax,%r13d
lea    0xe49(%rip),%r12
jmp    11e6 <hex_dump+0xb6>
nop
mov    $0x3,%esi
mov    $0x1,%edx
lea    0xe3b(%rip),%rdi
mov    %rbx,%rcx
call   1050 <fwrite@plt>
add    $0x1,%rbp
cmp    %r13,%rbp
jae    1160 <hex_dump+0x30>
cmp    %r15,%rbp
jae    11c0 <hex_dump+0x90>
mov    (%r14,%rbp,4),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11d9 <hex_dump+0xa9>
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 = zext 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 i32 %24, 16
%26 = icmp ult i32 %23, %25
br i1 %26, label %27, label %47
27: ; preds = %22
%28 = load i32, i32* %9
%29 = zext 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 = zext 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 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 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 %30, label %6
6: ; preds = %3, %26
%7 = phi i32 [ %9, %26 ], [ 0, %3 ]
%8 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = add i32 %7, 16
%10 = icmp eq i32 %7, -16
br i1 %10, label %26, label %11
11: ; preds = %6
%12 = zext i32 %7 to i64
%13 = zext i32 %9 to i64
br label %14
14: ; preds = %11, %23
%15 = phi i64 [ %12, %11 ], [ %24, %23 ]
%16 = icmp ult i64 %15, %2
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = getelementptr inbounds i32, i32* %4, i64 %15
%19 = load i32, i32* %18
%20 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %23
21: ; preds = %14
%22 = 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 %23
23: ; preds = %17, %21
%24 = add nuw nsw i64 %15, 1
%25 = icmp ult i64 %24, %13
br i1 %25, label %14, label %26
26: ; preds = %23, %6
%27 = phi i64 [ 0, %6 ], [ %13, %23 ]
%28 = tail call i32 @fputc(i32 10, i32* %0)
%29 = icmp ult i64 %27, %2
br i1 %29, label %6, label %30
30: ; preds = %26, %3
ret void
}