#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ stderr;
int toprint(unsigned char const);
void dump_mem(const void *ptr, int size) {
  const unsigned char *p = (const unsigned char *)ptr;
  int i;
  for (i = 0; i < size;) {
    char buf[0x81];
    char *writep = buf;
    int cell = 0;
    writep += sprintf(writep, "\t%04x: ", i);
    for (cell = 0; cell < 16; cell++) {
      if (i + cell < size)
        writep += sprintf(writep, "%02x", p[cell]);
      else
        writep += sprintf(writep, "  ");
      if (cell > 0 && (cell & 3) == 0) {
        *writep++ = ' ';
        *writep = 0;
      }
    }
    *writep++ = ' ';
    *writep = 0;
    for (cell = 0; cell < 16; cell++) {
      if (i + cell < size)
        writep += sprintf(writep, "%c", toprint(p[cell]));
      else
        writep += sprintf(writep, "  ");
    }
    fprintf(stderr, "%s\n", buf);
    i += 16;
    p += 16;
  }
}


x86 assembly (clang, -O0):
<dump_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    13a9 <dump_mem+0x279>
lea    -0xa0(%rbp),%rax
mov    %rax,-0xa8(%rbp)
movl   $0x0,-0xac(%rbp)
mov    -0xa8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    %eax,%ecx
mov    -0xa8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0xa8(%rbp)
movl   $0x0,-0xac(%rbp)
cmpl   $0x10,-0xac(%rbp)
jge    1290 <dump_mem+0x160>
mov    -0x1c(%rbp),%eax
add    -0xac(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    120b <dump_mem+0xdb>
mov    -0xa8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0xac(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    %eax,%ecx
mov    -0xa8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0xa8(%rbp)
jmp    1236 <dump_mem+0x106>
mov    -0xa8(%rbp),%rdi
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    %eax,%ecx
mov    -0xa8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0xa8(%rbp)
cmpl   $0x0,-0xac(%rbp)
jle    1277 <dump_mem+0x147>
mov    -0xac(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
jne    1277 <dump_mem+0x147>
mov    -0xa8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xa8(%rbp)
movb   $0x20,(%rax)
mov    -0xa8(%rbp),%rax
movb   $0x0,(%rax)
jmp    127c <dump_mem+0x14c>
mov    -0xac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xac(%rbp)
jmp    11ad <dump_mem+0x7d>
mov    -0xa8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xa8(%rbp)
movb   $0x20,(%rax)
mov    -0xa8(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0xac(%rbp)
cmpl   $0x10,-0xac(%rbp)
jge    1373 <dump_mem+0x243>
mov    -0x1c(%rbp),%eax
add    -0xac(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    132f <dump_mem+0x1ff>
mov    -0xa8(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0x18(%rbp),%rax
movslq -0xac(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1030 <toprint@plt>
mov    -0xb8(%rbp),%rdi
mov    %eax,%edx
lea    0xd03(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    %eax,%ecx
mov    -0xa8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0xa8(%rbp)
jmp    135a <dump_mem+0x22a>
mov    -0xa8(%rbp),%rdi
lea    0xcd0(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    %eax,%ecx
mov    -0xa8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0xa8(%rbp)
jmp    135f <dump_mem+0x22f>
mov    -0xac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xac(%rbp)
jmp    12bc <dump_mem+0x18c>
mov    0x2c66(%rip),%rax
mov    (%rax),%edi
lea    -0xa0(%rbp),%rdx
lea    0xc89(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x18(%rbp)
jmp    1151 <dump_mem+0x21>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_mem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %esi,0x4(%rsp)
test   %esi,%esi
jle    128c <dump_mem+0x15c>
mov    %rdi,%r12
mov    0x4(%rsp),%r15d
lea    0x10(%rsp),%rbx
xor    %r14d,%r14d
mov    %rdi,0x8(%rsp)
jmp    119c <dump_mem+0x6c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdx
call   1040 <fprintf@plt>
add    $0x10,%r14
cmp    0x4(%rsp),%r14d
jge    128c <dump_mem+0x15c>
mov    %rbx,%rdi
lea    0xe5a(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <sprintf@plt>
cltq
lea    (%rsp,%rax,1),%r13
add    $0x10,%r13
add    %r14,%r12
xor    %ebp,%ebp
lea    0xe42(%rip),%rbx
jmp    11da <dump_mem+0xaa>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    $0x10,%rbp
je     1230 <dump_mem+0x100>
lea    (%r14,%rbp,1),%rax
cmp    %r15,%rax
jge    1200 <dump_mem+0xd0>
movzbl (%r12,%rbp,1),%edx
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <sprintf@plt>
cltq
jmp    1211 <dump_mem+0xe1>
nopl   0x0(%rax)
movb   $0x0,0x2(%r13)
movw   $0x2020,0x0(%r13)
mov    $0x2,%eax
add    %rax,%r13
test   %rbp,%rbp
je     11d0 <dump_mem+0xa0>
mov    %ebp,%eax
and    $0x3,%eax
test   %rax,%rax
jne    11d0 <dump_mem+0xa0>
movw   $0x20,0x0(%r13)
add    $0x1,%r13
jmp    11d0 <dump_mem+0xa0>
movw   $0x20,0x0(%r13)
add    $0x1,%r13
mov    $0x10,%ebp
mov    %r14,%rbx
mov    0x8(%rsp),%r12
jmp    126e <dump_mem+0x13e>
nopw   0x0(%rax,%rax,1)
movb   $0x0,0x2(%r13)
movw   $0x2020,0x0(%r13)
add    $0x2,%r13
add    $0x1,%rbx
add    $0xffffffffffffffff,%rbp
je     1170 <dump_mem+0x40>
cmp    %r15,%rbx
jge    1250 <dump_mem+0x120>
movzbl (%r12,%rbx,1),%edi
call   1030 <toprint@plt>
mov    %al,0x0(%r13)
movb   $0x0,0x1(%r13)
add    $0x1,%r13
jmp    1260 <dump_mem+0x130>
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"\09%04x: \00"
@.str.1 = [5 x i8] c"%02x\00"
@.str.2 = [3 x i8] c" \00"
@.str.3 = [3 x i8] c"%c\00"
@stderr = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
define void @dump_mem(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [129 x i8]
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = load i8*, i8** %3
store i8* %10, i8** %5
store i32 0, i32* %6
br label %11
11: ; preds = %100, %2
%12 = load i32, i32* %6
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %108
15: ; preds = %11
%16 = getelementptr inbounds [129 x i8], [129 x i8]* %7, i64 0, i64 0
store i8* %16, i8** %8
store i32 0, i32* %9
%17 = load i8*, i8** %8
%18 = load i32, i32* %6
%19 = call i32 (i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i8*, i8** %8
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8, i8* %20, i64 %21
store i8* %22, i8** %8
store i32 0, i32* %9
br label %23
23: ; preds = %62, %15
%24 = load i32, i32* %9
%25 = icmp slt i32 %24, 16
br i1 %25, label %26, label %65
26: ; preds = %23
%27 = load i32, i32* %6
%28 = load i32, i32* %9
%29 = add nsw i32 %27, %28
%30 = load i32, i32* %4
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %44
32: ; preds = %26
%33 = load i8*, i8** %8
%34 = load i8*, i8** %5
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = call i32 (i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = load i8*, i8** %8
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds i8, i8* %41, i64 %42
store i8* %43, i8** %8
br label %50
44: ; preds = %26
%45 = load i8*, i8** %8
%46 = call i32 (i8*, i8*, ...) @sprintf(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%47 = load i8*, i8** %8
%48 = sext i32 %46 to i64
%49 = getelementptr inbounds i8, i8* %47, i64 %48
store i8* %49, i8** %8
br label %50
50: ; preds = %44, %32
%51 = load i32, i32* %9
%52 = icmp sgt i32 %51, 0
br i1 %52, label %53, label %61
53: ; preds = %50
%54 = load i32, i32* %9
%55 = and i32 %54, 3
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %53
%58 = load i8*, i8** %8
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %8
store i8 32, i8* %58
%60 = load i8*, i8** %8
store i8 0, i8* %60
br label %61
61: ; preds = %57, %53, %50
br label %62
62: ; preds = %61
%63 = load i32, i32* %9
%64 = add nsw i32 %63, 1
store i32 %64, i32* %9
br label %23
65: ; preds = %23
%66 = load i8*, i8** %8
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %8
store i8 32, i8* %66
%68 = load i8*, i8** %8
store i8 0, i8* %68
store i32 0, i32* %9
br label %69
69: ; preds = %97, %65
%70 = load i32, i32* %9
%71 = icmp slt i32 %70, 16
br i1 %71, label %72, label %100
72: ; preds = %69
%73 = load i32, i32* %6
%74 = load i32, i32* %9
%75 = add nsw i32 %73, %74
%76 = load i32, i32* %4
%77 = icmp slt i32 %75, %76
br i1 %77, label %78, label %90
78: ; preds = %72
%79 = load i8*, i8** %8
%80 = load i8*, i8** %5
%81 = load i32, i32* %9
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
%84 = load i8, i8* %83
%85 = call i32 @toprint(i8 zeroext %84)
%86 = call i32 (i8*, i8*, ...) @sprintf(i8* %79, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %85)
%87 = load i8*, i8** %8
%88 = sext i32 %86 to i64
%89 = getelementptr inbounds i8, i8* %87, i64 %88
store i8* %89, i8** %8
br label %96
90: ; preds = %72
%91 = load i8*, i8** %8
%92 = call i32 (i8*, i8*, ...) @sprintf(i8* %91, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%93 = load i8*, i8** %8
%94 = sext i32 %92 to i64
%95 = getelementptr inbounds i8, i8* %93, i64 %94
store i8* %95, i8** %8
br label %96
96: ; preds = %90, %78
br label %97
97: ; preds = %96
%98 = load i32, i32* %9
%99 = add nsw i32 %98, 1
store i32 %99, i32* %9
br label %69
100: ; preds = %69
%101 = load i32, i32* @stderr
%102 = getelementptr inbounds [129 x i8], [129 x i8]* %7, i64 0, i64 0
%103 = call i32 @fprintf(i32 %101, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %102)
%104 = load i32, i32* %6
%105 = add nsw i32 %104, 16
store i32 %105, i32* %6
%106 = load i8*, i8** %5
%107 = getelementptr inbounds i8, i8* %106, i64 16
store i8* %107, i8** %5
br label %11
108: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"\09%04x: \00"
@.str.1 = [5 x i8] c"%02x\00"
@.str.2 = [3 x i8] c" \00"
@stderr = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
define void @dump_mem(i8* nocapture %0, i32 %1) {
%3 = alloca [129 x i8]
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %66
5: ; preds = %2
%6 = getelementptr inbounds [129 x i8], [129 x i8]* %3, i64 0, i64 0
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %5, %59
%9 = phi i64 [ 0, %5 ], [ %62, %59 ]
%10 = phi i8* [ %0, %5 ], [ %63, %59 ]
%11 = trunc i64 %9 to i32
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [129 x i8], [129 x i8]* %3, i64 0, i64 %13
br label %15
15: ; preds = %8, %36
%16 = phi i64 [ 0, %8 ], [ %38, %36 ]
%17 = phi i8* [ %14, %8 ], [ %37, %36 ]
%18 = add nuw nsw i64 %16, %9
%19 = icmp slt i64 %18, %7
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = getelementptr inbounds i8, i8* %10, i64 %16
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %17, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = sext i32 %24 to i64
br label %27
26: ; preds = %15
br label %27
27: ; preds = %26, %20
%28 = phi i64 [ 2, %26 ], [ %25, %20 ]
%29 = getelementptr inbounds i8, i8* %17, i64 %28
%30 = icmp ne i64 %16, 0
%31 = and i64 %16, 3
%32 = icmp eq i64 %31, 0
%33 = and i1 %30, %32
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = getelementptr inbounds i8, i8* %29, i64 1
store i8 32, i8* %29
store i8 0, i8* %35
br label %36
36: ; preds = %27, %34
%37 = phi i8* [ %35, %34 ], [ %29, %27 ]
%38 = add nuw nsw i64 %16, 1
%39 = icmp eq i64 %38, 16
br i1 %39, label %40, label %15
40: ; preds = %36
%41 = getelementptr inbounds i8, i8* %37, i64 1
store i8 32, i8* %37
store i8 0, i8* %41
br label %42
42: ; preds = %40, %55
%43 = phi i64 [ 0, %40 ], [ %57, %55 ]
%44 = phi i8* [ %41, %40 ], [ %56, %55 ]
%45 = add nuw nsw i64 %43, %9
%46 = icmp slt i64 %45, %7
br i1 %46, label %47, label %53
47: ; preds = %42
%48 = getelementptr inbounds i8, i8* %10, i64 %43
%49 = load i8, i8* %48
%50 = call i32 @toprint(i8 zeroext %49)
%51 = trunc i32 %50 to i8
store i8 %51, i8* %44
%52 = getelementptr i8, i8* %44, i64 1
store i8 0, i8* %52
br label %55
53: ; preds = %42
%54 = getelementptr inbounds i8, i8* %44, i64 2
br label %55
55: ; preds = %47, %53
%56 = phi i8* [ %52, %47 ], [ %54, %53 ]
%57 = add nuw nsw i64 %43, 1
%58 = icmp eq i64 %57, 16
br i1 %58, label %59, label %42
59: ; preds = %55
%60 = load i32, i32* @stderr
%61 = call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%62 = add nuw i64 %9, 16
%63 = getelementptr inbounds i8, i8* %10, i64 16
%64 = trunc i64 %62 to i32
%65 = icmp slt i32 %64, %1
br i1 %65, label %8, label %66
66: ; preds = %59, %2
ret void
}