#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 dump_data(FILE *fp, const uint8_t *data, int len, const char *msg) {
  if (msg)
    fprintf(fp, "%s (%d): ", msg, len);
  if (!data || !len)
    return;
  int i;
  for (i = 0; i < len; i++) {
    fprintf(fp, "%02x ", data[i]);
    if (i % 16 == 15)
      fprintf(fp, "\n");
  }
  fprintf(fp, "\n");
}


x86 assembly (clang, -O0):
<dump_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     114b <dump_data+0x3b>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xebc(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
cmpq   $0x0,-0x10(%rbp)
je     1160 <dump_data+0x50>
cmpl   $0x0,-0x14(%rbp)
jne    1165 <dump_data+0x55>
jmp    11e0 <dump_data+0xd0>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ce <dump_data+0xbe>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe7c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
jne    11bb <dump_data+0xab>
mov    -0x8(%rbp),%rdi
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11c0 <dump_data+0xb0>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116c <dump_data+0x5c>
mov    -0x8(%rbp),%rdi
lea    0xe37(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_data>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rcx,%rcx
je     114b <dump_data+0x2b>
lea    0xec4(%rip),%rsi
mov    %rbx,%rdi
mov    %rcx,%rdx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %r14,%r14
je     11a1 <dump_data+0x81>
test   %ebp,%ebp
je     11a1 <dump_data+0x81>
jle    11aa <dump_data+0x8a>
mov    %ebp,%r12d
lea    0xeaa(%rip),%r15
xor    %ebp,%ebp
jmp    1179 <dump_data+0x59>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbp
cmp    %rbp,%r12
je     11aa <dump_data+0x8a>
mov    (%r14,%rbp,4),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebp,%eax
not    %eax
test   $0xf,%al
jne    1170 <dump_data+0x50>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
jmp    1170 <dump_data+0x50>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xa,%edi
mov    %rbx,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fputc@plt>

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

LLVM IR (-O2):
@.str = [10 x i8] c"%s (%d): \00"
@.str.1 = [6 x i8] c"%02x \00"
define void @dump_data(i32* nocapture %0, i32* %1, i32 %2, i8* %3) {
%5 = icmp eq i8* %3, null
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %2)
br label %8
8: ; preds = %6, %4
%9 = icmp ne i32* %1, null
%10 = icmp ne i32 %2, 0
%11 = and i1 %9, %10
br i1 %11, label %12, label %30
12: ; preds = %8
%13 = icmp sgt i32 %2, 0
br i1 %13, label %14, label %28
14: ; preds = %12
%15 = zext i32 %2 to i64
br label %16
16: ; preds = %14, %25
%17 = phi i64 [ 0, %14 ], [ %26, %25 ]
%18 = getelementptr inbounds i32, i32* %1, i64 %17
%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)
%21 = and i64 %17, 15
%22 = icmp eq i64 %21, 15
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = tail call i32 @fputc(i32 10, i32* %0)
br label %25
25: ; preds = %16, %23
%26 = add nuw nsw i64 %17, 1
%27 = icmp eq i64 %26, %15
br i1 %27, label %28, label %16
28: ; preds = %25, %12
%29 = tail call i32 @fputc(i32 10, i32* %0)
br label %30
30: ; preds = %8, %28
ret void
}