#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 *, unsigned char);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
void mymemdump(FILE *fd, char *p, int len) {
  int i;
  for (i = 0; i < len; i += 16) {
    fprintf(fd, "0x%016lX: ", (unsigned long)p);
    int remaining = len - i;
    if (remaining > 16)
      remaining = 16;
    char *end = p + remaining;
    while (p != end) {
      fprintf(fd, "%02X ", *(unsigned char *)p);
      p++;
    }
    for (int i = 0; i < (16 - remaining) * 3; i++)
      fputc(' ', fd);
    fputc(' ', fd);
    p -= remaining;
    while (p != end) {
      unsigned char c = *(unsigned char *)p;
      fprintf(fd, "%c", (c >= 32 && c <= 127) ? c : '.');
      p++;
    }
    fputc('\n', fd);
  }
}


x86 assembly (clang, -O0):
<mymemdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12ae <mymemdump+0x18e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
lea    0xeab(%rip),%rsi
movzbl %al,%edx
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
jle    1177 <mymemdump+0x57>
movl   $0x10,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     11bc <mymemdump+0x9c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
lea    0xe68(%rip),%rsi
movzbl (%rax),%edx
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1186 <mymemdump+0x66>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x10,%ecx
sub    -0x1c(%rbp),%ecx
imul   $0x3,%ecx,%ecx
cmp    %ecx,%eax
jge    11f5 <mymemdump+0xd5>
mov    -0x8(%rbp),%rsi
mov    $0x20,%edi
call   1030 <fputc@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c3 <mymemdump+0xa3>
mov    -0x8(%rbp),%rsi
mov    $0x20,%edi
call   1030 <fputc@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     1292 <mymemdump+0x172>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x2d(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
movzbl -0x2d(%rbp),%eax
cmp    $0x20,%eax
jl     125e <mymemdump+0x13e>
movzbl -0x2d(%rbp),%eax
cmp    $0x7f,%eax
jg     125e <mymemdump+0x13e>
movzbl -0x2d(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    126b <mymemdump+0x14b>
mov    $0x2e,%eax
mov    %eax,-0x3c(%rbp)
jmp    126b <mymemdump+0x14b>
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%eax
lea    0xd98(%rip),%rsi
movzbl %al,%edx
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1219 <mymemdump+0xf9>
mov    -0x8(%rbp),%rsi
mov    $0xa,%edi
call   1030 <fputc@plt>
mov    -0x18(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x18(%rbp)
jmp    113a <mymemdump+0x1a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mymemdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %edx,%edx
jle    12a1 <mymemdump+0x181>
mov    %rsi,%rbp
mov    %rdi,%r12
xor    %ebx,%ebx
lea    0xec6(%rip),%r13
mov    %edx,%eax
mov    %edx,0x4(%rsp)
jmp    117b <mymemdump+0x5b>
nopl   (%rax)
mov    $0xa,%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
mov    0x20(%rsp),%rbx
add    $0x10,%ebx
mov    0xc(%rsp),%eax
add    $0xfffffff0,%eax
mov    %r14,%rbp
mov    0x4(%rsp),%edx
cmp    %edx,%ebx
jge    12a1 <mymemdump+0x181>
cmp    $0x10,%eax
mov    $0x10,%r14d
mov    %eax,0xc(%rsp)
cmovl  %eax,%r14d
lea    (%r14,%r14,2),%eax
mov    $0x30,%r15d
sub    %eax,%r15d
cmp    $0x2,%r15d
mov    $0x1,%eax
cmovl  %eax,%r15d
movzbl %bpl,%edx
mov    %r12,%rdi
lea    0xe4c(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x4(%rsp),%edx
mov    %rbx,0x20(%rsp)
sub    %ebx,%edx
cmp    $0x10,%edx
mov    $0x10,%eax
cmovl  %edx,%eax
movslq %eax,%rcx
lea    (%rcx,%rbp,1),%rax
mov    %rax,0x10(%rsp)
test   %ecx,%ecx
mov    %rcx,0x18(%rsp)
je     1290 <mymemdump+0x170>
mov    %edx,0x8(%rsp)
movslq %r14d,%rbx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0x0(%rbp,%r14,1),%edx
mov    %r12,%rdi
mov    %r13,%rsi
call   1040 <fprintf@plt>
add    $0x1,%r14
cmp    %r14,%rbx
jne    1200 <mymemdump+0xe0>
mov    0x10(%rsp),%r14
mov    %r14,%rbp
mov    $0x2e,%ebx
mov    0x8(%rsp),%edx
cmp    $0xf,%edx
jg     1243 <mymemdump+0x123>
mov    $0x20,%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
add    $0xffffffff,%r15d
jne    1230 <mymemdump+0x110>
mov    $0x20,%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
sub    0x18(%rsp),%rbp
cmp    %r14,%rbp
je     1150 <mymemdump+0x30>
xchg   %ax,%ax
movzbl 0x0(%rbp),%eax
cmp    $0x20,%al
cmovl  %ebx,%eax
movzbl %al,%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
add    $0x1,%rbp
cmp    %r14,%rbp
jne    1260 <mymemdump+0x140>
jmp    1150 <mymemdump+0x30>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x2e,%ebx
mov    0x10(%rsp),%r14
cmp    $0xf,%edx
jle    1230 <mymemdump+0x110>
jmp    1243 <mymemdump+0x123>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"0x%016lX: \00"
@.str.1 = [6 x i8] c"%02X \00"
define void @mymemdump(i32* %0, i8* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %54
5: ; preds = %3, %49
%6 = phi i32 [ %53, %49 ], [ %2, %3 ]
%7 = phi i8* [ %20, %49 ], [ %1, %3 ]
%8 = phi i32 [ %51, %49 ], [ 0, %3 ]
%9 = call i32 @llvm.smin.i32(i32 %6, i32 16)
%10 = mul i32 %9, -3
%11 = add i32 %10, 48
%12 = call i32 @llvm.smax.i32(i32 %11, i32 1)
%13 = ptrtoint i8* %7 to i64
%14 = trunc i64 %13 to i8
%15 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8 zeroext %14)
%16 = sub nsw i32 %2, %8
%17 = icmp slt i32 %16, 16
%18 = select i1 %17, i32 %16, i32 16
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %7, i64 %19
%21 = icmp eq i32 %18, 0
br i1 %21, label %22, label %24
22: ; preds = %24, %5
%23 = phi i8* [ %7, %5 ], [ %20, %24 ]
br i1 %17, label %35, label %30
24: ; preds = %5, %24
%25 = phi i8* [ %28, %24 ], [ %7, %5 ]
%26 = load i8, i8* %25
%27 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %26)
%28 = getelementptr inbounds i8, i8* %25, i64 1
%29 = icmp eq i8* %28, %20
br i1 %29, label %22, label %24
30: ; preds = %35, %22
%31 = tail call i32 @fputc(i8 signext 32, i32* %0)
%32 = sub nsw i64 0, %19
%33 = getelementptr inbounds i8, i8* %23, i64 %32
%34 = icmp eq i8* %33, %20
br i1 %34, label %49, label %40
35: ; preds = %22, %35
%36 = phi i32 [ %38, %35 ], [ 0, %22 ]
%37 = tail call i32 @fputc(i8 signext 32, i32* %0)
%38 = add nuw nsw i32 %36, 1
%39 = icmp eq i32 %38, %12
br i1 %39, label %30, label %35
40: ; preds = %30, %40
%41 = phi i8* [ %47, %40 ], [ %33, %30 ]
%42 = load i8, i8* %41
%43 = icmp sgt i8 %42, 31
%44 = select i1 %43, i8 %42, i8 46
%45 = zext i8 %44 to i32
%46 = tail call i32 bitcast (i32 (i8, i32*)* @fputc to i32 (i32, i32*)*)(i32 %45, i32* %0)
%47 = getelementptr inbounds i8, i8* %41, i64 1
%48 = icmp eq i8* %47, %20
br i1 %48, label %49, label %40
49: ; preds = %40, %30
%50 = tail call i32 @fputc(i8 signext 10, i32* %0)
%51 = add nuw nsw i32 %8, 16
%52 = icmp slt i32 %51, %2
%53 = add i32 %6, -16
br i1 %52, label %5, label %54
54: ; preds = %49, %3
ret void
}