#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*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char);
int memdump2(char *memory, int len, int idx) {
  char buffer[4 * 16 + 2];
  memset(buffer, ' ', 4 * 16);
  buffer[4 * 16] = 0;
  buffer[(4 * 16) + 1] = 0;
  if (!(idx % 16) && (idx < len))
    printf("0x%x\t", idx);
  do {
    sprintf(&buffer[3 * (idx % 16)], "%.2X ", (*(memory + idx)) & 0xff);
    buffer[(3 * 16) + (idx % 16) + 1] =
        (((*(memory + idx) > 0x1f) && (*(memory + idx) < 0x7e))
             ? (*(memory + idx))
             : '.');
  } while ((++idx % 16) && (idx < len));
  buffer[3 * ((idx - 1) % 16) + 3] = ' ';
  printf("%s\n", buffer);
  return ((idx < len) ? memdump2(memory, len, idx) : 1);
}


x86 assembly (clang, -O0):
<memdump2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0x20,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
movb   $0x0,-0x20(%rbp)
movb   $0x0,-0x1f(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    119e <memdump2+0x5e>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119e <memdump2+0x5e>
mov    -0x10(%rbp),%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a3 <memdump2+0x63>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
imul   $0x3,%edx,%eax
cltq
lea    -0x60(%rbp),%rdi
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
lea    0xe34(%rip),%rsi
movsbl %al,%edx
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x1f,%eax
jle    1218 <memdump2+0xd8>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jge    1218 <memdump2+0xd8>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x64(%rbp)
jmp    1225 <memdump2+0xe5>
mov    $0x2e,%eax
mov    %eax,-0x64(%rbp)
jmp    1225 <memdump2+0xe5>
mov    -0x64(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%eax
mov    $0x10,%esi
cltd
idiv   %esi
mov    %edx,%eax
add    $0x30,%eax
add    $0x1,%eax
cltq
mov    %cl,-0x60(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0x10,%ecx
cltd
idiv   %ecx
xor    %eax,%eax
cmp    $0x0,%edx
mov    %al,-0x65(%rbp)
je     126e <memdump2+0x12e>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
setl   %al
mov    %al,-0x65(%rbp)
mov    -0x65(%rbp),%al
test   $0x1,%al
jne    11a3 <memdump2+0x63>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
imul   $0x3,%edx,%eax
add    $0x3,%eax
cltq
movb   $0x20,-0x60(%rbp,%rax,1)
lea    -0x60(%rbp),%rsi
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12c9 <memdump2+0x189>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <memdump2@plt>
mov    %eax,-0x6c(%rbp)
jmp    12d6 <memdump2+0x196>
mov    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    12d6 <memdump2+0x196>
mov    -0x6c(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memdump2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%rbp
lea    0x10(%rsp),%rdi
mov    $0x20,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
movw   $0x0,0x50(%rsp)
cmp    %r14d,%ebx
jge    119d <memdump2+0x4d>
mov    %ebx,%eax
and    $0xf,%eax
jne    119d <memdump2+0x4d>
lea    0xe6c(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movslq %ebx,%rax
mov    %r14d,0xc(%rsp)
movslq %r14d,%r13
add    $0x1,%rax
nopl   0x0(%rax)
lea    0xf(%rbx),%r15d
test   %ebx,%ebx
cmovns %ebx,%r15d
mov    %rax,%r14
and    $0xfffffff0,%r15d
mov    %ebx,%eax
sub    %r15d,%eax
cltq
lea    (%rax,%rax,2),%r12
movslq %r12d,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x10,%rdi
movsbl -0x1(%rbp,%r14,1),%edx
lea    0xe22(%rip),%rsi
call   1070 <sprintf@plt>
movzbl -0x1(%rbp,%r14,1),%eax
lea    -0x20(%rax),%ecx
cmp    $0x5e,%cl
mov    $0x2e,%ecx
cmovae %ecx,%eax
neg    %r15d
lea    (%rbx,%r15,1),%ecx
add    $0x31,%ecx
mov    %al,0x10(%rsp,%rcx,1)
add    $0x1,%ebx
cmp    %r13,%r14
jge    1222 <memdump2+0xd2>
mov    %r14d,%ecx
and    $0xf,%ecx
lea    0x1(%r14),%rax
test   %rcx,%rcx
jne    11b0 <memdump2+0x60>
lea    0x10(%rsp),%rdi
movb   $0x20,0x3(%r12,%rdi,1)
call   1030 <puts@plt>
cmp    %r13,%r14
jge    1245 <memdump2+0xf5>
mov    %rbp,%rdi
mov    0xc(%rsp),%esi
mov    %ebx,%edx
call   1060 <memdump2@plt>
mov    $0x1,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"0x%x\09\00"
@.str.1 = [6 x i8] c"%.2X \00"
define i32 @memdump2(i8* nocapture %0, i32 %1, i32 %2) {
%4 = alloca [66 x i8]
%5 = getelementptr inbounds [66 x i8], [66 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i8 signext 32, i32 64)
%7 = getelementptr inbounds [66 x i8], [66 x i8]* %4, i64 0, i64 64
store i8 0, i8* %7
%8 = getelementptr inbounds [66 x i8], [66 x i8]* %4, i64 0, i64 65
store i8 0, i8* %8
%9 = and i32 %2, 15
%10 = icmp eq i32 %9, 0
%11 = icmp slt i32 %2, %1
%12 = and i1 %11, %10
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %15
15: ; preds = %13, %3
%16 = sext i32 %2 to i64
%17 = sext i32 %1 to i64
br label %18
18: ; preds = %18, %15
%19 = phi i64 [ %35, %18 ], [ %16, %15 ]
%20 = trunc i64 %19 to i32
%21 = srem i32 %20, 16
%22 = mul nsw i32 %21, 3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [66 x i8], [66 x i8]* %4, i64 0, i64 %23
%25 = getelementptr inbounds i8, i8* %0, i64 %19
%26 = load i8, i8* %25
%27 = call i32 @sprintf(i8* %24, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 signext %26)
%28 = load i8, i8* %25
%29 = add i8 %28, -32
%30 = icmp ult i8 %29, 94
%31 = select i1 %30, i8 %28, i8 46
%32 = add nsw i32 %21, 49
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds [66 x i8], [66 x i8]* %4, i64 0, i64 %33
store i8 %31, i8* %34
%35 = add nsw i64 %19, 1
%36 = and i64 %35, 15
%37 = icmp ne i64 %36, 0
%38 = icmp slt i64 %35, %17
%39 = and i1 %38, %37
br i1 %39, label %18, label %40
40: ; preds = %18
%41 = add nsw i32 %22, 3
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [66 x i8], [66 x i8]* %4, i64 0, i64 %42
store i8 32, i8* %43
%44 = call i32 @puts(i8* %5)
br i1 %38, label %45, label %48
45: ; preds = %40
%46 = trunc i64 %35 to i32
%47 = call i32 @memdump2(i8* %0, i32 %1, i32 %46)
br label %48
48: ; preds = %40, %45
ret i32 1
}