#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 *, ...);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void hexdump(void *pos, int len) {
  unsigned char *cpos = pos, *cpos1;
  int lines = (len + 15) >> 4;
  while (lines--) {
    int len1 = len, i;
    fprintf(stderr, "#R# %0x  ", (int)cpos - (int)pos);
    cpos1 = cpos;
    for (i = 0; i < 16; i++) {
      if (len1 > 0) {
        fprintf(stderr, "%02x ", *(cpos++));
      } else {
        fprintf(stderr, "   ");
      }
      len1--;
    }
    fputs("  ", stderr);
    cpos = cpos1;
    for (i = 0; i < 16; i++) {
      if (len > 0) {
        unsigned char ch = (*(cpos++));
        if ((ch < 32) || (ch > 127))
          ch = '.';
        fputc(ch, stderr);
      }
      len--;
    }
    fputs("\n", stderr);
  }
  fputc('\n', stderr);
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0xf,%eax
sar    $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x24(%rbp)
cmp    $0x0,%eax
je     12be <hexdump+0x18e>
mov    -0xc(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
mov    -0x8(%rbp),%rax
sub    %eax,%edx
lea    0xe77(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x10,-0x2c(%rbp)
jge    120f <hexdump+0xdf>
cmpl   $0x0,-0x28(%rbp)
jle    11e1 <hexdump+0xb1>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movzbl (%rax),%edx
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11f8 <hexdump+0xc8>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119f <hexdump+0x6f>
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
lea    0xdf2(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x10,-0x2c(%rbp)
jge    12a4 <hexdump+0x174>
cmpl   $0x0,-0xc(%rbp)
jle    128d <hexdump+0x15d>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x2d(%rbp)
movzbl -0x2d(%rbp),%eax
cmp    $0x20,%eax
jl     1275 <hexdump+0x145>
movzbl -0x2d(%rbp),%eax
cmp    $0x7f,%eax
jle    1279 <hexdump+0x149>
movb   $0x2e,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
mov    0x2d5d(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1040 <fputc@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1233 <hexdump+0x103>
mov    0x2d35(%rip),%rax
mov    (%rax),%esi
lea    0xd60(%rip),%rdi
call   1030 <fputs@plt>
jmp    1153 <hexdump+0x23>
mov    0x2d1b(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1040 <fputc@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %rdi,0x10(%rsp)
lea    0xf(%rbx),%eax
cmp    $0x10,%eax
jae    116e <hexdump+0x3e>
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fputc@plt>
sar    $0x4,%eax
mov    0x2e68(%rip),%r14
lea    0xe8b(%rip),%rbp
mov    0x10(%rsp),%r12
jmp    11ae <hexdump+0x7e>
cs nopw 0x0(%rax,%rax,1)
add    $0xfffffff0,%ebx
mov    (%r14),%esi
lea    0xe77(%rip),%rdi
call   1030 <fputs@plt>
mov    0xc(%rsp),%eax
add    $0xffffffff,%eax
mov    %r15,%rbp
je     114d <hexdump+0x1d>
mov    %eax,0xc(%rsp)
mov    (%r14),%edi
mov    %r12d,%edx
sub    0x10(%rsp),%edx
lea    0xe3d(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %r15d,%r15d
mov    %r12,%r13
jmp    11f8 <hexdump+0xc8>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xe29(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0xffffffff,%r15d
cmp    $0xfffffff0,%r15d
je     1220 <hexdump+0xf0>
lea    (%rbx,%r15,1),%eax
mov    (%r14),%edi
test   %eax,%eax
jle    11e0 <hexdump+0xb0>
movzbl 0x0(%r13),%edx
add    $0x1,%r13
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11ee <hexdump+0xbe>
nopl   0x0(%rax,%rax,1)
mov    %rbp,%r15
mov    (%r14),%esi
lea    0xde4(%rip),%rdi
call   1030 <fputs@plt>
xor    %ebp,%ebp
mov    $0x2e,%r13d
jmp    124c <hexdump+0x11c>
nopl   0x0(%rax)
add    $0xffffffff,%ebp
cmp    $0xfffffff0,%ebp
je     1190 <hexdump+0x60>
lea    (%rbx,%rbp,1),%eax
test   %eax,%eax
jle    1240 <hexdump+0x110>
movzbl (%r12),%eax
add    $0x1,%r12
cmp    $0x20,%al
cmovl  %r13d,%eax
mov    (%r14),%esi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    1240 <hexdump+0x110>

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

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