#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*/ dumpbinary(char, int);
int /*<<< orphan*/ printf(char *, ...);
int dumpmem(void *p, int len) {
  if (NULL == p) {
    return 0;
  }
  printf("address : [%08x]:\n", (unsigned int)p);
  char *pc = (char *)p;
  int i = 0;
  for (i = 0; i < len; i++) {
    dumpbinary(pc[i], 8);
    printf(" ");
    if ((i + 1) % 4 == 0) {
      printf("\n");
    }
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<dumpmem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1147 <dumpmem+0x27>
movl   $0x0,-0x4(%rbp)
jmp    11ee <dumpmem+0xce>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d9 <dumpmem+0xb9>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    $0x8,%esi
movsbl (%rax,%rcx,1),%edi
call   1040 <dumpbinary@plt>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11c6 <dumpmem+0xa6>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11cb <dumpmem+0xab>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1171 <dumpmem+0x51>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dumpmem>:
test   %rdi,%rdi
je     11ab <dumpmem+0x7b>
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xebb(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    119d <dumpmem+0x6d>
mov    %ebp,%ebp
neg    %rbp
mov    $0x1,%ebx
jmp    1172 <dumpmem+0x42>
nop
lea    (%rbx,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
je     119d <dumpmem+0x6d>
movsbl -0x1(%r14,%rbx,1),%edi
mov    $0x8,%esi
call   1050 <dumpbinary@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
test   $0x3,%bl
jne    1160 <dumpmem+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1160 <dumpmem+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
pop    %rbx
pop    %r14
pop    %rbp
xor    %eax,%eax
ret

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

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