#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*/ printf(char *, ...);
void test_memprint(char *addr, long len) {
  long i;
  for (i = 0; i < len; i++) {
    if ((i % 16) == 0) {
      if (i)
        printf("\n");
      printf("%08lx: ", (long)(addr + i));
    }
    printf("%02x", (unsigned char)*(addr + i));
    if (((i + 1) % 2) == 0)
      printf(" ");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<test_memprint>:
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
jge    11d7 <test_memprint+0xc7>
mov    -0x18(%rbp),%rax
mov    $0x10,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    117d <test_memprint+0x6d>
cmpq   $0x0,-0x18(%rbp)
je     1167 <test_memprint+0x57>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rsi
add    -0x18(%rbp),%rsi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    11c1 <test_memprint+0xb1>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c6 <test_memprint+0xb6>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <test_memprint+0x18>
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_memprint>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rsi,%rsi
jle    115e <test_memprint+0x3e>
mov    %rsi,%r14
mov    %rdi,%r13
lea    0xec5(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x0(%r13),%esi
lea    0xeb7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%r14
jne    1171 <test_memprint+0x51>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>
mov    $0x1,%ebx
lea    0xe83(%rip),%r15
lea    0xe84(%rip),%r12
jmp    1195 <test_memprint+0x75>
cs nopw 0x0(%rax,%rax,1)
cmp    %rbx,%r14
je     115e <test_memprint+0x3e>
test   $0xf,%bl
jne    11b2 <test_memprint+0x92>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    (%rbx,%r13,1),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x0(%r13,%rbx,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
test   $0x1,%bl
jne    1190 <test_memprint+0x70>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1190 <test_memprint+0x70>

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

LLVM IR (-O2):
@.str.1 = [8 x i8] c"%08lx: \00"
@.str.2 = [5 x i8] c"%02x\00"
define void @test_memprint(i8* %0, i64 %1) {
%3 = icmp sgt i64 %1, 0
br i1 %3, label %4, label %32
4: ; preds = %2
%5 = ptrtoint i8* %0 to i64
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 %5)
%7 = load i8, i8* %0
%8 = zext i8 %7 to i32
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = icmp eq i64 %1, 1
br i1 %10, label %32, label %11
11: ; preds = %4, %30
%12 = phi i64 [ %25, %30 ], [ 1, %4 ]
%13 = and i64 %12, 15
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = tail call i32 @putchar(i32 10)
%17 = getelementptr inbounds i8, i8* %0, i64 %12
%18 = ptrtoint i8* %17 to i64
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 %18)
br label %20
20: ; preds = %15, %11
%21 = getelementptr inbounds i8, i8* %0, i64 %12
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = add nuw nsw i64 %12, 1
%26 = and i64 %25, 1
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = tail call i32 @putchar(i32 32)
br label %30
30: ; preds = %20, %28
%31 = icmp eq i64 %25, %1
br i1 %31, label %32, label %11
32: ; preds = %30, %4, %2
%33 = tail call i32 @putchar(i32 10)
ret void
}