#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 dump(const void *buff, int count) {
  int i = 0;
  printf("memory dump of %d bytes from address 0x%x\n", count, buff);
  for (i = 0; i < count; i++) {
    unsigned char ch = *(const unsigned char *)buff;
    printf("0x%02X ", ch);
    if ((i + 1) % 16 == 0)
      printf("\n");
    buff = (const char *)buff + 1;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rdx
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a8 <dump+0x98>
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%esi
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    118e <dump+0x7e>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1142 <dump+0x32>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r15
lea    0xecd(%rip),%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    117a <dump+0x5a>
mov    %ebp,%ebp
lea    0xee1(%rip),%r14
xor    %ebx,%ebx
jmp    1158 <dump+0x38>
xchg   %ax,%ax
add    $0x1,%rbx
cmp    %ebx,%ebp
je     117a <dump+0x5a>
movzbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1(%rbx),%eax
test   $0xf,%al
jne    1150 <dump+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1150 <dump+0x30>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"memory dump of %d bytes from address 0x%x\0A\00"
@.str.1 = [8 x i8] c"0x%02X \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @dump(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%7 = load i32, i32* %4
%8 = load i8*, i8** %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %7, i8* %8)
store i32 0, i32* %5
br label %10
10: ; preds = %29, %2
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %32
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
store i8 %16, i8* %6
%17 = load i8, i8* %6
%18 = zext i8 %17 to i32
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
%22 = srem i32 %21, 16
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %14
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %14
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8* %28, i8** %3
br label %29
29: ; preds = %26
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %10
32: ; preds = %10
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [43 x i8] c"memory dump of %d bytes from address 0x%x\0A\00"
@.str.1 = [8 x i8] c"0x%02X \00"
define void @dump(i8* %0, i32 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %1, i8* %0)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %19
5: ; preds = %2, %16
%6 = phi i8* [ %17, %16 ], [ %0, %2 ]
%7 = phi i32 [ %11, %16 ], [ 0, %2 ]
%8 = load i8, i8* %6
%9 = zext i8 %8 to i32
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = add nuw nsw i32 %7, 1
%12 = and i32 %11, 15
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %5
%15 = tail call i32 @putchar(i32 10)
br label %16
16: ; preds = %14, %5
%17 = getelementptr inbounds i8, i8* %6, i64 1
%18 = icmp eq i32 %11, %1
br i1 %18, label %19, label %5
19: ; preds = %16, %2
%20 = tail call i32 @putchar(i32 10)
ret void
}