#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 memory_hexdump_alien(void *ptr, size_t len) {
  size_t pos;
  for (pos = 0; pos < len; pos++) {
    if ((pos & 0x0F) == 0)
      fprintf(stderr, "%06zX:  ", pos);
    fprintf(stderr, "%02X ", ((char *)ptr)[pos]);
    if ((pos & 0x0F) == 0x0F)
      fprintf(stderr, "\n");
  }
  if ((pos & 0x0F))
    fprintf(stderr, "\n");
}


x86 assembly (clang, -O0):
<memory_hexdump_alien>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11c5 <memory_hexdump_alien+0xb5>
mov    -0x18(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    1163 <memory_hexdump_alien+0x53>
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xea4(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%rax
and    $0xf,%rax
cmp    $0xf,%rax
jne    11af <memory_hexdump_alien+0x9f>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11b4 <memory_hexdump_alien+0xa4>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <memory_hexdump_alien+0x18>
mov    -0x18(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
je     11ee <memory_hexdump_alien+0xde>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memory_hexdump_alien>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     11b5 <memory_hexdump_alien+0xa5>
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2eaf(%rip),%r15
lea    0xed1(%rip),%r12
xor    %ebp,%ebp
jmp    1149 <memory_hexdump_alien+0x39>
nopl   0x0(%rax)
add    $0x1,%rbp
cmp    %rbp,%rbx
je     1191 <memory_hexdump_alien+0x81>
mov    %rbp,%r13
and    $0xf,%r13
jne    1166 <memory_hexdump_alien+0x56>
mov    (%r15),%edi
lea    0xea4(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r15),%edi
movsbl (%r14,%rbp,1),%edx
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    $0xf,%r13
jne    1140 <memory_hexdump_alien+0x30>
mov    (%r15),%edi
lea    0xe87(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1140 <memory_hexdump_alien+0x30>
test   $0xf,%bl
je     11b5 <memory_hexdump_alien+0xa5>
mov    (%r15),%edi
lea    0xe6f(%rip),%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprintf@plt>
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"%06zX: \00"
@.str.1 = [6 x i8] c"%02X \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @memory_hexdump_alien(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
store i64 0, i64* %5
br label %6
6: ; preds = %33, %2
%7 = load i64, i64* %5
%8 = load i64, i64* %4
%9 = icmp ult i64 %7, %8
br i1 %9, label %10, label %36
10: ; preds = %6
%11 = load i64, i64* %5
%12 = and i64 %11, 15
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = load i64, i64* %5
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %16)
br label %18
18: ; preds = %14, %10
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %3
%21 = load i64, i64* %5
%22 = getelementptr inbounds i8, i8* %20, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = load i64, i64* %5
%27 = and i64 %26, 15
%28 = icmp eq i64 %27, 15
br i1 %28, label %29, label %32
29: ; preds = %18
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %29, %18
br label %33
33: ; preds = %32
%34 = load i64, i64* %5
%35 = add i64 %34, 1
store i64 %35, i64* %5
br label %6
36: ; preds = %6
%37 = load i64, i64* %5
%38 = and i64 %37, 15
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* @stderr
%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, %36
ret void
}

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