#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 */

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void test_dumpmem(const void *buf, size_t len) {
  const unsigned char *ucbuf = buf;
  size_t i;
  for (i = 0; i < len; ++i) {
    if ((i % 16) == 0) {
      fprintf(stderr, "\n       ");
    } else if ((i % 8) == 0) {
      fprintf(stderr, "  ");
    }
    fprintf(stderr, " %02x", ucbuf[i]);
  }
}


x86 assembly (clang, -O0):
<test_dumpmem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11ce <test_dumpmem+0xbe>
mov    -0x20(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    116c <test_dumpmem+0x5c>
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    119a <test_dumpmem+0x8a>
mov    -0x20(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
jne    1195 <test_dumpmem+0x85>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    119a <test_dumpmem+0x8a>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe53(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1130 <test_dumpmem+0x20>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_dumpmem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     117f <test_dumpmem+0x6f>
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xed3(%rip),%r12
mov    0x2eac(%rip),%r13
lea    0xece(%rip),%r15
xor    %ebp,%ebp
jmp    1167 <test_dumpmem+0x57>
nop
mov    0x0(%r13),%edi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%r13),%edi
movzbl (%r14,%rbp,1),%edx
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
je     117f <test_dumpmem+0x6f>
mov    %r12,%rsi
test   $0xf,%bpl
je     1140 <test_dumpmem+0x30>
lea    0xe8f(%rip),%rsi
test   $0x7,%bpl
jne    114b <test_dumpmem+0x3b>
jmp    1140 <test_dumpmem+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [9 x i8] c"\0A \00"
@.str.1 = [3 x i8] c" \00"
@.str.2 = [6 x i8] c" %02x\00"
define void @test_dumpmem(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i8*, i8** %3
store i8* %7, i8** %5
store i64 0, i64* %6
br label %8
8: ; preds = %35, %2
%9 = load i64, i64* %6
%10 = load i64, i64* %4
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %38
12: ; preds = %8
%13 = load i64, i64* %6
%14 = urem i64 %13, 16
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %27
19: ; preds = %12
%20 = load i64, i64* %6
%21 = urem i64 %20, 8
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %23, %19
br label %27
27: ; preds = %26, %16
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %5
%30 = load i64, i64* %6
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %27
%36 = load i64, i64* %6
%37 = add i64 %36, 1
store i64 %37, i64* %6
br label %8
38: ; preds = %8
ret void
}

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