#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
void h2o_dump_memory(FILE *fp, const char *buf, size_t len) {
  size_t i, j;
  for (i = 0; i < len; i += 16) {
    fprintf(fp, "%08zx", i);
    for (j = 0; j != 16; ++j) {
      if (i + j < len)
        fprintf(fp, " %02x", (int)(unsigned char)buf[i + j]);
      else
        fprintf(fp, "   ");
    }
    fprintf(fp, " ");
    for (j = 0; j != 16 && i + j < len; ++j) {
      int ch = buf[i + j];
      fputc(' ' <= ch && ch < 0x7f ? ch : '.', fp);
    }
    fprintf(fp, "\n");
  }
}


x86 assembly (clang, -O0):
<h2o_dump_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    12a3 <h2o_dump_memory+0x183>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xea7(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movq   $0x0,-0x28(%rbp)
cmpq   $0x10,-0x28(%rbp)
je     11d4 <h2o_dump_memory+0xb4>
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11ac <h2o_dump_memory+0x8c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11be <h2o_dump_memory+0x9e>
mov    -0x8(%rbp),%rdi
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11c3 <h2o_dump_memory+0xa3>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1168 <h2o_dump_memory+0x48>
mov    -0x8(%rbp),%rdi
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movq   $0x0,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x10,-0x28(%rbp)
mov    %al,-0x2d(%rbp)
je     1210 <h2o_dump_memory+0xf0>
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
setb   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    1220 <h2o_dump_memory+0x100>
jmp    1280 <h2o_dump_memory+0x160>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x20,%eax
cmp    -0x2c(%rbp),%eax
jg     1256 <h2o_dump_memory+0x136>
cmpl   $0x7f,-0x2c(%rbp)
jge    1256 <h2o_dump_memory+0x136>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    1263 <h2o_dump_memory+0x143>
mov    $0x2e,%eax
mov    %eax,-0x34(%rbp)
jmp    1263 <h2o_dump_memory+0x143>
mov    -0x34(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <fputc@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11ee <h2o_dump_memory+0xce>
mov    -0x8(%rbp),%rdi
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x20(%rbp)
jmp    113c <h2o_dump_memory+0x1c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<h2o_dump_memory>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     123a <h2o_dump_memory+0x10a>
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeb2(%rip),%rbp
xor    %r12d,%r12d
jmp    1181 <h2o_dump_memory+0x51>
nopl   0x0(%rax)
mov    $0xa,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
add    $0x10,%r12
add    $0x10,%r14
cmp    %r15,%r12
mov    %r13,%rbp
jae    123a <h2o_dump_memory+0x10a>
mov    %rbx,%rdi
lea    0xe75(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %r13d,%r13d
jmp    11c3 <h2o_dump_memory+0x93>
nopw   0x0(%rax,%rax,1)
mov    $0x3,%esi
mov    $0x1,%edx
lea    0xe5b(%rip),%rdi
mov    %rbx,%rcx
call   1050 <fwrite@plt>
add    $0x1,%r13
cmp    $0x10,%r13
je     11e0 <h2o_dump_memory+0xb0>
lea    (%r12,%r13,1),%rax
cmp    %r15,%rax
jae    11a0 <h2o_dump_memory+0x70>
movzbl (%r14,%r13,1),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11b9 <h2o_dump_memory+0x89>
mov    %rbp,%r13
mov    $0x20,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%r12,%rbp,1),%rax
cmp    %r15,%rax
jae    1160 <h2o_dump_memory+0x30>
movzbl (%r14,%rbp,1),%eax
lea    -0x20(%rax),%ecx
cmp    $0x5f,%cl
mov    $0x2e,%ecx
cmovae %ecx,%eax
movzbl %al,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
add    $0x1,%rbp
cmp    $0x10,%rbp
jne    1200 <h2o_dump_memory+0xd0>
jmp    1160 <h2o_dump_memory+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%08zx\00"
@.str.1 = [6 x i8] c" %02x\00"
@.str.2 = [4 x i8] c" \00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [2 x i8] c"\0A\00"
define void @h2o_dump_memory(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i64 0, i64* %7
br label %10
10: ; preds = %84, %3
%11 = load i64, i64* %7
%12 = load i64, i64* %6
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %87
14: ; preds = %10
%15 = load i32*, i32** %4
%16 = load i64, i64* %7
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %16)
store i64 0, i64* %8
br label %18
18: ; preds = %41, %14
%19 = load i64, i64* %8
%20 = icmp ne i64 %19, 16
br i1 %20, label %21, label %44
21: ; preds = %18
%22 = load i64, i64* %7
%23 = load i64, i64* %8
%24 = add i64 %22, %23
%25 = load i64, i64* %6
%26 = icmp ult i64 %24, %25
br i1 %26, label %27, label %37
27: ; preds = %21
%28 = load i32*, i32** %4
%29 = load i8*, i8** %5
%30 = load i64, i64* %7
%31 = load i64, i64* %8
%32 = add i64 %30, %31
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %35)
br label %40
37: ; preds = %21
%38 = load i32*, i32** %4
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %37, %27
br label %41
41: ; preds = %40
%42 = load i64, i64* %8
%43 = add i64 %42, 1
store i64 %43, i64* %8
br label %18
44: ; preds = %18
%45 = load i32*, i32** %4
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i64 0, i64* %8
br label %47
47: ; preds = %78, %44
%48 = load i64, i64* %8
%49 = icmp ne i64 %48, 16
br i1 %49, label %50, label %56
50: ; preds = %47
%51 = load i64, i64* %7
%52 = load i64, i64* %8
%53 = add i64 %51, %52
%54 = load i64, i64* %6
%55 = icmp ult i64 %53, %54
br label %56
56: ; preds = %50, %47
%57 = phi i1 [ false, %47 ], [ %55, %50 ]
br i1 %57, label %58, label %81
58: ; preds = %56
%59 = load i8*, i8** %5
%60 = load i64, i64* %7
%61 = load i64, i64* %8
%62 = add i64 %60, %61
%63 = getelementptr inbounds i8, i8* %59, i64 %62
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
store i32 %65, i32* %9
%66 = load i32, i32* %9
%67 = icmp sle i32 32, %66
br i1 %67, label %68, label %73
68: ; preds = %58
%69 = load i32, i32* %9
%70 = icmp slt i32 %69, 127
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = load i32, i32* %9
br label %74
73: ; preds = %68, %58
br label %74
74: ; preds = %73, %71
%75 = phi i32 [ %72, %71 ], [ 46, %73 ]
%76 = load i32*, i32** %4
%77 = call i32 @fputc(i32 %75, i32* %76)
br label %78
78: ; preds = %74
%79 = load i64, i64* %8
%80 = add i64 %79, 1
store i64 %80, i64* %8
br label %47
81: ; preds = %56
%82 = load i32*, i32** %4
%83 = call i32 (i32*, i8*, ...) @fprintf(i32* %82, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %84
84: ; preds = %81
%85 = load i64, i64* %7
%86 = add i64 %85, 16
store i64 %86, i64* %7
br label %10
87: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%08zx\00"
@.str.1 = [6 x i8] c" %02x\00"
@.str.2 = [4 x i8] c" \00"
define void @h2o_dump_memory(i32* nocapture %0, i8* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %42, label %5
5: ; preds = %3, %38
%6 = phi i64 [ %40, %38 ], [ 0, %3 ]
%7 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %6)
br label %8
8: ; preds = %5, %19
%9 = phi i64 [ 0, %5 ], [ %20, %19 ]
%10 = add nuw nsw i64 %9, %6
%11 = icmp ult i64 %10, %2
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %1, i64 %10
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %19
17: ; preds = %8
%18 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 3, i64 1, i32* %0)
br label %19
19: ; preds = %12, %17
%20 = add nuw nsw i64 %9, 1
%21 = icmp eq i64 %20, 16
br i1 %21, label %22, label %8
22: ; preds = %19
%23 = tail call i32 @fputc(i32 32, i32* %0)
br label %24
24: ; preds = %22, %28
%25 = phi i64 [ 0, %22 ], [ %36, %28 ]
%26 = add nuw nsw i64 %25, %6
%27 = icmp ult i64 %26, %2
br i1 %27, label %28, label %38
28: ; preds = %24
%29 = getelementptr inbounds i8, i8* %1, i64 %26
%30 = load i8, i8* %29
%31 = add i8 %30, -32
%32 = icmp ult i8 %31, 95
%33 = select i1 %32, i8 %30, i8 46
%34 = zext i8 %33 to i32
%35 = tail call i32 @fputc(i32 %34, i32* %0)
%36 = add nuw nsw i64 %25, 1
%37 = icmp eq i64 %36, 16
br i1 %37, label %38, label %24
38: ; preds = %28, %24
%39 = tail call i32 @fputc(i32 10, i32* %0)
%40 = add i64 %6, 16
%41 = icmp ult i64 %40, %2
br i1 %41, label %5, label %42
42: ; preds = %38, %3
ret void
}