#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 mem_get_size(void *);
int /*<<< orphan*/ printf(char *, ...);
void mem_Dump(void *mem) {
  printf("chunk id:%d\nsize:%d\nhex:\n", mem, mem_get_size(mem));
  for (int b = 0; b < mem_get_size(mem); b++) {
    printf("%2x ", ((unsigned char *)mem)[b]);
  }
  printf("\nraw:\n");
  for (int b = 0; b < mem_get_size(mem); b++) {
    printf("%c", ((unsigned char *)mem)[b]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<mem_Dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <mem_get_size@plt>
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <mem_get_size@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    119c <mem_Dump+0x7c>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1158 <mem_Dump+0x38>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <mem_get_size@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    11f5 <mem_Dump+0xd5>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11b1 <mem_Dump+0x91>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_Dump>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1060 <mem_get_size@plt>
lea    0xeac(%rip),%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1060 <mem_get_size@plt>
test   %eax,%eax
jle    11a2 <mem_Dump+0x62>
lea    0xea7(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1060 <mem_get_size@plt>
cltq
cmp    %rax,%rbx
jl     1180 <mem_Dump+0x40>
lea    0xe76(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1060 <mem_get_size@plt>
test   %eax,%eax
jle    11dd <mem_Dump+0x9d>
xor    %ebx,%ebx
nopl   0x0(%rax)
movzbl (%r15,%rbx,1),%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1060 <mem_get_size@plt>
cltq
cmp    %rax,%rbx
jl     11c0 <mem_Dump+0x80>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [26 x i8] c"chunk id:%d\0Asize:%d\0Ahex:\0A\00"
@.str.1 = [5 x i8] c"%2x \00"
@str = [6 x i8] c"\0Araw:\00"
define void @mem_Dump(i8* %0) {
%2 = tail call i32 @mem_get_size(i8* %0)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %2)
%4 = tail call i32 @mem_get_size(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %10, %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @mem_get_size(i8* %0)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %22, label %20
10: ; preds = %1, %10
%11 = phi i64 [ %16, %10 ], [ 0, %1 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = add nuw nsw i64 %11, 1
%17 = tail call i32 @mem_get_size(i8* %0)
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %10, label %6
20: ; preds = %22, %6
%21 = tail call i32 @putchar(i32 10)
ret void
22: ; preds = %6, %22
%23 = phi i64 [ %28, %22 ], [ 0, %6 ]
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = tail call i32 @putchar(i32 %26)
%28 = add nuw nsw i64 %23, 1
%29 = tail call i32 @mem_get_size(i8* %0)
%30 = sext i32 %29 to i64
%31 = icmp slt i64 %28, %30
br i1 %31, label %22, label %20
}