#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ test_newline();
void memory_dump(uint8_t addr[], uint32_t size) {
  size_t i;
  if (size & 3) {
    size = (size & ~3) + 4;
  }
  addr = (uint8_t *)((uint32_t)addr & ~3);
  printf("%08p-%08p", addr, addr + size);
  for (i = 0; size > 0; size -= 4, addr += 4, i++) {
    if (i == 0) {
      test_newline();
      printf("%08p ", addr);
    } else if (i == 2) {
      printf(" ");
    } else if (i == 3) {
      i = -1;
    }
    printf("%02x %02x %02x %02x ", addr[0], addr[1], addr[2], addr[3]);
  }
  test_newline();
}


x86 assembly (clang, -O0):
<memory_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
je     114a <memory_dump+0x2a>
mov    -0xc(%rbp),%eax
and    $0xfffffffc,%eax
add    $0x4,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
and    $0xfffffffc,%eax
cltq
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x8(%rbp),%rdx
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    123e <memory_dump+0x11e>
cmpq   $0x0,-0x18(%rbp)
jne    11b3 <memory_dump+0x93>
mov    $0x0,%al
call   1040 <test_newline@plt>
mov    -0x8(%rbp),%rsi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ee <memory_dump+0xce>
cmpq   $0x2,-0x18(%rbp)
jne    11d1 <memory_dump+0xb1>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e9 <memory_dump+0xc9>
cmpq   $0x3,-0x18(%rbp)
jne    11e4 <memory_dump+0xc4>
movq   $0xffffffffffffffff,-0x18(%rbp)
ff
jmp    11e9 <memory_dump+0xc9>
jmp    11ee <memory_dump+0xce>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%r8d
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1180 <memory_dump+0x60>
mov    $0x0,%al
call   1040 <test_newline@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memory_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0x4(%rsi),%r13d
and    $0xfffffffc,%r13d
test   $0x3,%sil
cmove  %esi,%r13d
movslq %edi,%rbx
and    $0xfffffffffffffffc,%rbx
movslq %r13d,%rbp
lea    (%rbx,%rbp,4),%rdx
lea    0xea0(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    1201 <memory_dump+0xd1>
add    $0x4,%r13d
lea    0xe93(%rip),%r14
lea    0xe86(%rip),%r15
mov    $0xffffffffffffffff,%r12
xor    %ebp,%ebp
jmp    11c0 <memory_dump+0x90>
nop
cmp    $0x3,%rbp
cmove  %r12,%rbp
mov    (%rbx),%esi
mov    0x4(%rbx),%edx
mov    0x8(%rbx),%ecx
mov    0xc(%rbx),%r8d
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%rbx
add    $0x1,%rbp
add    $0xfffffffc,%r13d
cmp    $0x4,%r13d
jle    1201 <memory_dump+0xd1>
cmp    $0x2,%rbp
je     11f0 <memory_dump+0xc0>
test   %rbp,%rbp
jne    1190 <memory_dump+0x60>
xor    %eax,%eax
call   1050 <test_newline@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %ebp,%ebp
jmp    1198 <memory_dump+0x68>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    $0x2,%ebp
jmp    1198 <memory_dump+0x68>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <test_newline@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"%08p-%08p\00"
@.str.1 = [6 x i8] c"%08p \00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [21 x i8] c"%02x %02x %02x %02x \00"
define void @memory_dump(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i64
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = and i32 %6, 3
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* %4
%11 = and i32 %10, -4
%12 = add nsw i32 %11, 4
store i32 %12, i32* %4
br label %13
13: ; preds = %9, %2
%14 = load i32*, i32** %3
%15 = ptrtoint i32* %14 to i32
%16 = and i32 %15, -4
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i32*
store i32* %18, i32** %3
%19 = load i32*, i32** %3
%20 = load i32*, i32** %3
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %19, i32* %23)
store i64 0, i64* %5
br label %25
25: ; preds = %60, %13
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %67
28: ; preds = %25
%29 = load i64, i64* %5
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = call i32 (...) @test_newline()
%33 = load i32*, i32** %3
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %33)
br label %46
35: ; preds = %28
%36 = load i64, i64* %5
%37 = icmp eq i64 %36, 2
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %45
40: ; preds = %35
%41 = load i64, i64* %5
%42 = icmp eq i64 %41, 3
br i1 %42, label %43, label %44
43: ; preds = %40
store i64 -1, i64* %5
br label %44
44: ; preds = %43, %40
br label %45
45: ; preds = %44, %38
br label %46
46: ; preds = %45, %31
%47 = load i32*, i32** %3
%48 = getelementptr inbounds i32, i32* %47, i64 0
%49 = load i32, i32* %48
%50 = load i32*, i32** %3
%51 = getelementptr inbounds i32, i32* %50, i64 1
%52 = load i32, i32* %51
%53 = load i32*, i32** %3
%54 = getelementptr inbounds i32, i32* %53, i64 2
%55 = load i32, i32* %54
%56 = load i32*, i32** %3
%57 = getelementptr inbounds i32, i32* %56, i64 3
%58 = load i32, i32* %57
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %49, i32 %52, i32 %55, i32 %58)
br label %60
60: ; preds = %46
%61 = load i32, i32* %4
%62 = sub nsw i32 %61, 4
store i32 %62, i32* %4
%63 = load i32*, i32** %3
%64 = getelementptr inbounds i32, i32* %63, i64 4
store i32* %64, i32** %3
%65 = load i64, i64* %5
%66 = add i64 %65, 1
store i64 %66, i64* %5
br label %25
67: ; preds = %25
%68 = call i32 (...) @test_newline()
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"%08p-%08p\00"
@.str.1 = [6 x i8] c"%08p \00"
@.str.3 = [21 x i8] c"%02x %02x %02x %02x \00"
define void @memory_dump(i32* %0, i32 %1) {
%3 = and i32 %1, 3
%4 = icmp eq i32 %3, 0
%5 = add i32 %1, 4
%6 = and i32 %5, -4
%7 = select i1 %4, i32 %1, i32 %6
%8 = ptrtoint i32* %0 to i64
%9 = shl i64 %8, 32
%10 = ashr exact i64 %9, 32
%11 = and i64 %10, -4
%12 = inttoptr i64 %11 to i32*
%13 = sext i32 %7 to i64
%14 = getelementptr inbounds i32, i32* %12, i64 %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %12, i32* %14)
%16 = icmp sgt i32 %7, 0
br i1 %16, label %17, label %43
17: ; preds = %2, %29
%18 = phi i64 [ %41, %29 ], [ 0, %2 ]
%19 = phi i32 [ %39, %29 ], [ %7, %2 ]
%20 = phi i32* [ %40, %29 ], [ %12, %2 ]
switch i64 %18, label %26 [
i64 0, label %21
i64 2, label %24
]
21: ; preds = %17
%22 = tail call i32 (...) @test_newline()
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %20)
br label %29
24: ; preds = %17
%25 = tail call i32 @putchar(i32 32)
br label %29
26: ; preds = %17
%27 = icmp eq i64 %18, 3
%28 = select i1 %27, i64 -1, i64 %18
br label %29
29: ; preds = %24, %26, %21
%30 = phi i64 [ 0, %21 ], [ 2, %24 ], [ %28, %26 ]
%31 = load i32, i32* %20
%32 = getelementptr inbounds i32, i32* %20, i64 1
%33 = load i32, i32* %32
%34 = getelementptr inbounds i32, i32* %20, i64 2
%35 = load i32, i32* %34
%36 = getelementptr inbounds i32, i32* %20, i64 3
%37 = load i32, i32* %36
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %33, i32 %35, i32 %37)
%39 = add nsw i32 %19, -4
%40 = getelementptr inbounds i32, i32* %20, i64 4
%41 = add i64 %30, 1
%42 = icmp sgt i32 %19, 4
br i1 %42, label %17, label %43
43: ; preds = %29, %2
%44 = tail call i32 (...) @test_newline()
ret void
}