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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void dump_mem(FILE *fp, const unsigned char *buf, int len, const char *desc) {
  int i = 0;
  if (desc)
    fprintf(fp, "%s:\n", desc);
  fprintf(fp, "--------------------------------------------------------\n");
  for (i = 0; i < len; i++) {
    fprintf(fp, "0x%02x ", (unsigned char)buf[i]);
    if ((i + 1) % 16 == 0)
      fprintf(fp, "\n");
  }
  fprintf(fp, "\n--------------------------------------------------------\n");
}


x86 assembly (clang, -O0):
<dump_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     114f <dump_mem+0x3f>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xeb8(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xeb4(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ce <dump_mem+0xbe>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11bb <dump_mem+0xab>
mov    -0x8(%rbp),%rdi
lea    0xe92(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11c0 <dump_mem+0xb0>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1168 <dump_mem+0x58>
mov    -0x8(%rbp),%rdi
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_mem>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r12
test   %rcx,%rcx
je     115a <dump_mem+0x2a>
lea    0xeb3(%rip),%rsi
mov    %r12,%rdi
mov    %rcx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xead(%rip),%rdi
mov    $0x1,%ebp
mov    $0x39,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1050 <fwrite@plt>
test   %r15d,%r15d
jle    11ca <dump_mem+0x9a>
mov    %r15d,%ebx
neg    %rbx
lea    0xe7b(%rip),%r15
jmp    11a2 <dump_mem+0x72>
nopl   0x0(%rax)
lea    (%rbx,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%rbp
cmp    $0x1,%rax
je     11ca <dump_mem+0x9a>
movzbl -0x1(%r14,%rbp,1),%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
test   $0xf,%bpl
jne    1190 <dump_mem+0x60>
mov    $0xa,%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
jmp    1190 <dump_mem+0x60>
lea    0xe3c(%rip),%rdi
mov    $0x3a,%esi
mov    $0x1,%edx
mov    %r12,%rcx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fwrite@plt>

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

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