#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*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ hexword(size_t, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
void hexdump(const unsigned char memory[], size_t length, FILE *fp) {
  size_t first = 0;
  size_t final = 0x10;
  size_t block = 0x10;
  size_t group = 0x10;
  size_t field = sizeof(unsigned);
  size_t offset = length;
  while (first < length) {
    hexword(first, field, fp);
    for (offset = first; offset < final; offset++) {
      putc(' ', fp);
      if ((offset % group) == 0) {
        putc(' ', fp);
      }
      if (offset < length) {
        putc("0123456789ABCDEF"[(memory[offset] >> 4) & 0x0F], fp);
        putc("0123456789ABCDEF"[(memory[offset] >> 0) & 0x0F], fp);
      } else {
        putc(' ', fp);
        putc(' ', fp);
      }
    }
    putc(' ', fp);
    for (offset = first; offset < final; offset++) {
      unsigned c = memory[offset];
      if ((c < 0x20) || (c > 0x7E)) {
        c = '.';
      }
      if ((offset % group) == 0) {
        putc(' ', fp);
      }
      if (offset < length) {
        putc(c, fp);
      } else {
        putc(' ', fp);
      }
    }
    putc('\n', fp);
    first += block;
    final += block;
  }
  fflush(fp);
  return;
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x10,-0x28(%rbp)
movq   $0x10,-0x30(%rbp)
movq   $0x10,-0x38(%rbp)
movq   $0x4,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1359 <hexdump+0x229>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <hexword@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1276 <hexdump+0x146>
mov    -0x18(%rbp),%rsi
mov    $0x20,%edi
call   1030 <putc@plt>
mov    -0x48(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x38(%rbp)
cmp    $0x0,%rdx
jne    11db <hexdump+0xab>
mov    -0x18(%rbp),%rsi
mov    $0x20,%edi
call   1030 <putc@plt>
mov    -0x48(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1244 <hexdump+0x114>
mov    -0x8(%rbp),%rax
mov    -0x48(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
sar    $0x4,%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xdfb(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1030 <putc@plt>
mov    -0x8(%rbp),%rax
mov    -0x48(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
sar    $0x0,%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xdd0(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1030 <putc@plt>
jmp    1260 <hexdump+0x130>
mov    -0x18(%rbp),%rsi
mov    $0x20,%edi
call   1030 <putc@plt>
mov    -0x18(%rbp),%rsi
mov    $0x20,%edi
call   1030 <putc@plt>
jmp    1265 <hexdump+0x135>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    119b <hexdump+0x6b>
mov    -0x18(%rbp),%rsi
mov    $0x20,%edi
call   1030 <putc@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    132e <hexdump+0x1fe>
mov    -0x8(%rbp),%rax
mov    -0x48(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x4c(%rbp)
cmpl   $0x20,-0x4c(%rbp)
jb     12bd <hexdump+0x18d>
cmpl   $0x7e,-0x4c(%rbp)
jbe    12c4 <hexdump+0x194>
movl   $0x2e,-0x4c(%rbp)
mov    -0x48(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x38(%rbp)
cmp    $0x0,%rdx
jne    12e8 <hexdump+0x1b8>
mov    -0x18(%rbp),%rsi
mov    $0x20,%edi
call   1030 <putc@plt>
mov    -0x48(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    130a <hexdump+0x1da>
mov    -0x4c(%rbp),%eax
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1030 <putc@plt>
jmp    1318 <hexdump+0x1e8>
mov    -0x18(%rbp),%rsi
mov    $0x20,%edi
call   1030 <putc@plt>
jmp    131d <hexdump+0x1ed>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    128c <hexdump+0x15c>
mov    -0x18(%rbp),%rsi
mov    $0xa,%edi
call   1030 <putc@plt>
mov    -0x30(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1174 <hexdump+0x44>
mov    -0x18(%rbp),%rdi
call   1040 <fflush@plt>
add    $0x50,%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    %rdx,%r13
test   %rsi,%rsi
je     12f8 <hexdump+0x1c8>
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x10,%r12d
xor    %ebx,%ebx
jmp    1183 <hexdump+0x53>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
mov    %r13,%rsi
call   1030 <putc@plt>
mov    0x8(%rsp),%rbx
add    $0x10,%rbx
add    $0x10,%r12
cmp    %r14,%rbx
jae    12f8 <hexdump+0x1c8>
mov    $0x4,%esi
mov    %rbx,%rdi
mov    %r13,%rdx
call   1050 <hexword@plt>
mov    $0x20,%edi
mov    %r13,%rsi
call   1030 <putc@plt>
mov    %rbx,0x8(%rsp)
cmp    %r12,%rbx
jae    1160 <hexdump+0x30>
mov    %r12,0x10(%rsp)
mov    $0x20,%edi
mov    %r13,%rsi
call   1030 <putc@plt>
mov    0x8(%rsp),%r12
movzbl (%r15,%r12,1),%eax
shr    $0x4,%rax
lea    0xe2f(%rip),%rbp
movsbl (%rax,%rbp,1),%edi
mov    %r13,%rsi
call   1030 <putc@plt>
movzbl (%r15,%r12,1),%eax
and    $0xf,%eax
movsbl (%rax,%rbp,1),%edi
mov    %r13,%rsi
call   1030 <putc@plt>
or     $0x1,%r12
mov    $0xf,%ebp
jmp    1224 <hexdump+0xf4>
nopl   0x0(%rax)
mov    $0x20,%edi
mov    %r13,%rsi
call   1030 <putc@plt>
mov    $0x20,%al
movsbl %al,%edi
mov    %r13,%rsi
call   1030 <putc@plt>
add    $0x1,%r12
add    $0xffffffffffffffff,%rbp
je     1260 <hexdump+0x130>
mov    $0x20,%edi
mov    %r13,%rsi
call   1030 <putc@plt>
cmp    %r14,%r12
jae    1200 <hexdump+0xd0>
movzbl (%r15,%r12,1),%eax
shr    $0x4,%rax
lea    0xdba(%rip),%rbx
movsbl (%rax,%rbx,1),%edi
mov    %r13,%rsi
call   1030 <putc@plt>
movzbl (%r15,%r12,1),%eax
and    $0xf,%eax
movzbl (%rax,%rbx,1),%eax
jmp    120f <hexdump+0xdf>
mov    $0x20,%edi
mov    %r13,%rsi
call   1030 <putc@plt>
mov    0x10(%rsp),%r12
cmp    %r12,0x8(%rsp)
jae    1160 <hexdump+0x30>
mov    0x8(%rsp),%rbp
movzbl (%r15,%rbp,1),%ebx
lea    -0x7f(%rbx),%eax
cmp    $0xa1,%al
mov    $0x2e,%eax
cmovb  %eax,%ebx
mov    $0x20,%edi
mov    %r13,%rsi
call   1030 <putc@plt>
movsbl %bl,%edi
mov    %r13,%rsi
call   1030 <putc@plt>
mov    $0x20,%edx
or     $0x1,%rbp
mov    $0xf,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%r15,%rbp,1),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
mov    $0x2e,%ecx
cmovb  %ecx,%eax
cmp    %r14,%rbp
cmovae %edx,%eax
movsbl %al,%edi
mov    %r13,%rsi
call   1030 <putc@plt>
mov    $0x20,%edx
add    $0x1,%rbp
add    $0xffffffffffffffff,%rbx
jne    12c0 <hexdump+0x190>
jmp    1160 <hexdump+0x30>
mov    %r13,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fflush@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"0123456789ABCDEF\00"
define void @hexdump(i8* %0, i64 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32* %2, i32** %6
store i64 0, i64* %7
store i64 16, i64* %8
store i64 16, i64* %9
store i64 16, i64* %10
store i64 4, i64* %11
%14 = load i64, i64* %5
store i64 %14, i64* %12
br label %15
15: ; preds = %121, %3
%16 = load i64, i64* %7
%17 = load i64, i64* %5
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %130
19: ; preds = %15
%20 = load i64, i64* %7
%21 = load i64, i64* %11
%22 = load i32*, i32** %6
%23 = call i32 @hexword(i64 %20, i64 %21, i32* %22)
%24 = load i64, i64* %7
store i64 %24, i64* %12
br label %25
25: ; preds = %74, %19
%26 = load i64, i64* %12
%27 = load i64, i64* %8
%28 = icmp ult i64 %26, %27
br i1 %28, label %29, label %77
29: ; preds = %25
%30 = load i32*, i32** %6
%31 = call i32 @putc(i8 signext 32, i32* %30)
%32 = load i64, i64* %12
%33 = load i64, i64* %10
%34 = urem i64 %32, %33
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %29
%37 = load i32*, i32** %6
%38 = call i32 @putc(i8 signext 32, i32* %37)
br label %39
39: ; preds = %36, %29
%40 = load i64, i64* %12
%41 = load i64, i64* %5
%42 = icmp ult i64 %40, %41
br i1 %42, label %43, label %68
43: ; preds = %39
%44 = load i8*, i8** %4
%45 = load i64, i64* %12
%46 = getelementptr inbounds i8, i8* %44, i64 %45
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = ashr i32 %48, 4
%50 = and i32 %49, 15
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = load i32*, i32** %6
%55 = call i32 @putc(i8 signext %53, i32* %54)
%56 = load i8*, i8** %4
%57 = load i64, i64* %12
%58 = getelementptr inbounds i8, i8* %56, i64 %57
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = ashr i32 %60, 0
%62 = and i32 %61, 15
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %63
%65 = load i8, i8* %64
%66 = load i32*, i32** %6
%67 = call i32 @putc(i8 signext %65, i32* %66)
br label %73
68: ; preds = %39
%69 = load i32*, i32** %6
%70 = call i32 @putc(i8 signext 32, i32* %69)
%71 = load i32*, i32** %6
%72 = call i32 @putc(i8 signext 32, i32* %71)
br label %73
73: ; preds = %68, %43
br label %74
74: ; preds = %73
%75 = load i64, i64* %12
%76 = add i64 %75, 1
store i64 %76, i64* %12
br label %25
77: ; preds = %25
%78 = load i32*, i32** %6
%79 = call i32 @putc(i8 signext 32, i32* %78)
%80 = load i64, i64* %7
store i64 %80, i64* %12
br label %81
81: ; preds = %118, %77
%82 = load i64, i64* %12
%83 = load i64, i64* %8
%84 = icmp ult i64 %82, %83
br i1 %84, label %85, label %121
85: ; preds = %81
%86 = load i8*, i8** %4
%87 = load i64, i64* %12
%88 = getelementptr inbounds i8, i8* %86, i64 %87
%89 = load i8, i8* %88
%90 = zext i8 %89 to i32
store i32 %90, i32* %13
%91 = load i32, i32* %13
%92 = icmp ult i32 %91, 32
br i1 %92, label %96, label %93
93: ; preds = %85
%94 = load i32, i32* %13
%95 = icmp ugt i32 %94, 126
br i1 %95, label %96, label %97
96: ; preds = %93, %85
store i32 46, i32* %13
br label %97
97: ; preds = %96, %93
%98 = load i64, i64* %12
%99 = load i64, i64* %10
%100 = urem i64 %98, %99
%101 = icmp eq i64 %100, 0
br i1 %101, label %102, label %105
102: ; preds = %97
%103 = load i32*, i32** %6
%104 = call i32 @putc(i8 signext 32, i32* %103)
br label %105
105: ; preds = %102, %97
%106 = load i64, i64* %12
%107 = load i64, i64* %5
%108 = icmp ult i64 %106, %107
br i1 %108, label %109, label %114
109: ; preds = %105
%110 = load i32, i32* %13
%111 = trunc i32 %110 to i8
%112 = load i32*, i32** %6
%113 = call i32 @putc(i8 signext %111, i32* %112)
br label %117
114: ; preds = %105
%115 = load i32*, i32** %6
%116 = call i32 @putc(i8 signext 32, i32* %115)
br label %117
117: ; preds = %114, %109
br label %118
118: ; preds = %117
%119 = load i64, i64* %12
%120 = add i64 %119, 1
store i64 %120, i64* %12
br label %81
121: ; preds = %81
%122 = load i32*, i32** %6
%123 = call i32 @putc(i8 signext 10, i32* %122)
%124 = load i64, i64* %9
%125 = load i64, i64* %7
%126 = add i64 %125, %124
store i64 %126, i64* %7
%127 = load i64, i64* %9
%128 = load i64, i64* %8
%129 = add i64 %128, %127
store i64 %129, i64* %8
br label %15
130: ; preds = %15
%131 = load i32*, i32** %6
%132 = call i32 @fflush(i32* %131)
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789ABCDEF\00"
define void @hexdump(i8* nocapture %0, i64 %1, i32* %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %79, label %5
5: ; preds = %3, %74
%6 = phi i64 [ %76, %74 ], [ 0, %3 ]
%7 = phi i64 [ %77, %74 ], [ 16, %3 ]
%8 = tail call i32 @hexword(i64 %6, i64 4, i32* %2)
%9 = icmp ult i64 %6, %7
%10 = tail call i32 @putc(i8 signext 32, i32* %2)
br i1 %9, label %11, label %74
11: ; preds = %5
%12 = tail call i32 @putc(i8 signext 32, i32* %2)
%13 = getelementptr inbounds i8, i8* %0, i64 %6
%14 = load i8, i8* %13
%15 = lshr i8 %14, 4
%16 = zext i8 %15 to i64
%17 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = tail call i32 @putc(i8 signext %18, i32* %2)
%20 = load i8, i8* %13
%21 = and i8 %20, 15
%22 = zext i8 %21 to i64
%23 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = tail call i32 @putc(i8 signext %24, i32* %2)
%26 = or i64 %6, 1
br label %27
27: ; preds = %46, %11
%28 = phi i64 [ %49, %46 ], [ %26, %11 ]
%29 = tail call i32 @putc(i8 signext 32, i32* %2)
%30 = icmp ult i64 %28, %1
br i1 %30, label %31, label %44
31: ; preds = %27
%32 = getelementptr inbounds i8, i8* %0, i64 %28
%33 = load i8, i8* %32
%34 = lshr i8 %33, 4
%35 = zext i8 %34 to i64
%36 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = tail call i32 @putc(i8 signext %37, i32* %2)
%39 = load i8, i8* %32
%40 = and i8 %39, 15
%41 = zext i8 %40 to i64
%42 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %41
%43 = load i8, i8* %42
br label %46
44: ; preds = %27
%45 = tail call i32 @putc(i8 signext 32, i32* %2)
br label %46
46: ; preds = %31, %44
%47 = phi i8 [ %43, %31 ], [ 32, %44 ]
%48 = tail call i32 @putc(i8 signext %47, i32* %2)
%49 = add i64 %28, 1
%50 = icmp eq i64 %49, %7
br i1 %50, label %51, label %27
51: ; preds = %46
%52 = tail call i32 @putc(i8 signext 32, i32* %2)
br i1 %9, label %53, label %74
53: ; preds = %51
%54 = getelementptr inbounds i8, i8* %0, i64 %6
%55 = load i8, i8* %54
%56 = add i8 %55, -127
%57 = icmp ult i8 %56, -95
%58 = select i1 %57, i8 46, i8 %55
%59 = tail call i32 @putc(i8 signext 32, i32* %2)
%60 = tail call i32 @putc(i8 signext %58, i32* %2)
%61 = or i64 %6, 1
br label %62
62: ; preds = %62, %53
%63 = phi i64 [ %72, %62 ], [ %61, %53 ]
%64 = getelementptr inbounds i8, i8* %0, i64 %63
%65 = load i8, i8* %64
%66 = add i8 %65, -127
%67 = icmp ult i8 %66, -95
%68 = select i1 %67, i8 46, i8 %65
%69 = icmp ult i64 %63, %1
%70 = select i1 %69, i8 %68, i8 32
%71 = tail call i32 @putc(i8 signext %70, i32* %2)
%72 = add i64 %63, 1
%73 = icmp eq i64 %72, %7
br i1 %73, label %74, label %62
74: ; preds = %62, %5, %51
%75 = tail call i32 @putc(i8 signext 10, i32* %2)
%76 = add i64 %6, 16
%77 = add i64 %7, 16
%78 = icmp ult i64 %76, %1
br i1 %78, label %5, label %79
79: ; preds = %74, %3
%80 = tail call i32 @fflush(i32* %2)
ret void
}