#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*/ hexstr;
typedef int /*<<< orphan*/ charstr;
typedef int /*<<< orphan*/ bytestr;
typedef int /*<<< orphan*/ addrstr;

/* Variables and functions */
scalar_t__ isprint(unsigned char);
int /*<<< orphan*/ printf(char *, char *, char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned char);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
void hex_dump(void *data, int size) {
  unsigned char *p = (unsigned char *)data;
  unsigned char c;
  int n;
  char bytestr[4] = {0};
  char addrstr[10] = {0};
  char hexstr[16 * 3 + 5] = {0};
  char charstr[16 * 1 + 5] = {0};
  for (n = 1; n <= size; n++) {
    if (n % 16 == 1) {
      snprintf(addrstr, sizeof(addrstr), "%.4x",
               (unsigned int)((unsigned char *)p - (unsigned char *)data));
    }
    c = *p;
    if (isprint(c) == 0) {
      c = '.';
    }
    snprintf(bytestr, sizeof(bytestr), "%02X ", *p);
    strncat(hexstr, bytestr, sizeof(hexstr) - strlen(hexstr) - 1);
    snprintf(bytestr, sizeof(bytestr), "%c", c);
    strncat(charstr, bytestr, sizeof(charstr) - strlen(charstr) - 1);
    if (n % 16 == 0) {
      printf("[%4.4s]   %-50.50s  %s\n", addrstr, hexstr, charstr);
      hexstr[0] = 0;
      charstr[0] = 0;
    } else if (n % 8 == 0) {
      strncat(hexstr, "  ", sizeof(hexstr) - strlen(hexstr) - 1);
      strncat(charstr, " ", sizeof(charstr) - strlen(charstr) - 1);
    }
    p++;
  }
  if (strlen(hexstr) > 0) {
    printf("[%4.4s]   %-50.50s  %s\n", addrstr, hexstr, charstr);
  }
}


x86 assembly (clang, -O0):
<hex_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    -0x24(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    -0x2e(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x35,%edx
call   1060 <memset@plt>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x15,%edx
call   1060 <memset@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     13d0 <hex_dump+0x270>
mov    -0x20(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1207 <hex_dump+0xa7>
lea    -0x2e(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    $0xa,%esi
lea    0xe01(%rip),%rdx
movzbl %al,%ecx
call   1050 <snprintf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%edi
call   1080 <isprint@plt>
cmp    $0x0,%rax
jne    1227 <hex_dump+0xc7>
movb   $0x2e,-0x19(%rbp)
lea    -0x24(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    $0x4,%esi
lea    0xdca(%rip),%rdx
movzbl (%rax),%ecx
call   1050 <snprintf@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0xb0(%rbp)
lea    -0x24(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0x70(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0xb0(%rbp),%rdi
mov    -0xa8(%rbp),%rsi
movslq %eax,%rcx
mov    $0x35,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1070 <strncat@plt>
lea    -0x24(%rbp),%rdi
mov    $0x4,%esi
lea    0xd75(%rip),%rdx
movzbl -0x19(%rbp),%ecx
call   1050 <snprintf@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0xa0(%rbp)
lea    -0x24(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x90(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0xa0(%rbp),%rdi
mov    -0x98(%rbp),%rsi
movslq %eax,%rcx
mov    $0x15,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1070 <strncat@plt>
mov    -0x20(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1327 <hex_dump+0x1c7>
lea    -0x2e(%rbp),%rsi
lea    -0x70(%rbp),%rdx
lea    -0x90(%rbp),%rcx
lea    0xcfc(%rip),%rdi
call   1040 <printf@plt>
movb   $0x0,-0x70(%rbp)
movb   $0x0,-0x90(%rbp)
jmp    13b6 <hex_dump+0x256>
mov    -0x20(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    13b1 <hex_dump+0x251>
lea    -0x70(%rbp),%rax
mov    %rax,-0xc0(%rbp)
lea    -0x70(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0xc0(%rbp),%rdi
movslq %eax,%rcx
mov    $0x35,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
lea    0xcb8(%rip),%rsi
call   1070 <strncat@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    -0x90(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0xb8(%rbp),%rdi
movslq %eax,%rcx
mov    $0x15,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
lea    0xc7b(%rip),%rsi
call   1070 <strncat@plt>
jmp    13b6 <hex_dump+0x256>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c4 <hex_dump+0x64>
lea    -0x70(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jle    13fd <hex_dump+0x29d>
lea    -0x2e(%rbp),%rsi
lea    -0x70(%rbp),%rdx
lea    -0x90(%rbp),%rcx
lea    0xc16(%rip),%rdi
call   1040 <printf@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rdi,0x18(%rsp)
movl   $0x0,0xc(%rsp)
movw   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movq   $0x0,0x6d(%rsp)
movaps %xmm0,0x20(%rsp)
movq   $0x0,0x2d(%rsp)
test   %esi,%esi
jle    12fb <hex_dump+0x1ab>
mov    %esi,%eax
mov    %rax,0x10(%rsp)
xor    %r15d,%r15d
lea    0x40(%rsp),%r13
jmp    11ea <hex_dump+0x9a>
nopl   0x0(%rax)
lea    0xe47(%rip),%rdi
mov    %rsp,%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1040 <printf@plt>
movb   $0x0,0x40(%rsp)
movb   $0x0,0x20(%rsp)
cmp    %r15d,0x10(%rsp)
je     12fb <hex_dump+0x1ab>
mov    %r13,%rbx
mov    %r15,%r14
add    $0x1,%r15
mov    %r15d,%ebp
and    $0xf,%ebp
cmp    $0x1,%ebp
jne    1217 <hex_dump+0xc7>
movzbl %r14b,%ecx
mov    %rsp,%rdi
mov    $0xa,%esi
lea    0xdee(%rip),%rdx
call   1050 <snprintf@plt>
mov    0x18(%rsp),%r13
movzbl 0x0(%r13,%r14,1),%r12d
mov    %r12d,%edi
call   1070 <isprint@plt>
test   %rax,%rax
mov    $0x2e,%eax
cmove  %eax,%r12d
movzbl 0x0(%r13,%r14,1),%ecx
lea    0xc(%rsp),%r14
mov    %r14,%rdi
mov    $0x4,%esi
lea    0xdb5(%rip),%rdx
call   1050 <snprintf@plt>
mov    %rbx,%r13
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    $0x34,%edx
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strncat@plt>
mov    %r14,%rdi
mov    $0x4,%esi
lea    0xd8a(%rip),%rdx
mov    %r12d,%ecx
call   1050 <snprintf@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    $0x14,%edx
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strncat@plt>
test   %ebp,%ebp
je     11c0 <hex_dump+0x70>
test   $0x7,%r15b
jne    11df <hex_dump+0x8f>
mov    %r13,%rdi
call   1030 <strlen@plt>
mov    $0x34,%edx
sub    %eax,%edx
mov    %r13,%rdi
lea    0xd53(%rip),%rsi
call   1060 <strncat@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    $0x14,%edx
sub    %eax,%edx
mov    %rbx,%rdi
lea    0xd36(%rip),%rsi
call   1060 <strncat@plt>
jmp    11df <hex_dump+0x8f>
lea    0x40(%rsp),%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1322 <hex_dump+0x1d2>
lea    0xcfe(%rip),%rdi
mov    %rsp,%rsi
lea    0x40(%rsp),%rdx
lea    0x20(%rsp),%rcx
call   1040 <printf@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%.4x\00"
@.str.1 = [6 x i8] c"%02X \00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [24 x i8] c"[%4.4s] %-50.50s %s\0A\00"
@.str.4 = [3 x i8] c" \00"
@.str.5 = [2 x i8] c" \00"
define void @hex_dump(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32
%8 = alloca [4 x i8]
%9 = alloca [10 x i8]
%10 = alloca [53 x i8]
%11 = alloca [21 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%12 = load i8*, i8** %3
store i8* %12, i8** %5
%13 = bitcast [4 x i8]* %8 to i8*
%14 = bitcast [10 x i8]* %9 to i8*
%15 = bitcast [53 x i8]* %10 to i8*
%16 = bitcast [21 x i8]* %11 to i8*
store i32 1, i32* %7
br label %17
17: ; preds = %103, %2
%18 = load i32, i32* %7
%19 = load i32, i32* %4
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %106
21: ; preds = %17
%22 = load i32, i32* %7
%23 = srem i32 %22, 16
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %35
25: ; preds = %21
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%27 = load i8*, i8** %5
%28 = load i8*, i8** %3
%29 = ptrtoint i8* %27 to i64
%30 = ptrtoint i8* %28 to i64
%31 = sub i64 %29, %30
%32 = trunc i64 %31 to i32
%33 = trunc i32 %32 to i8
%34 = call i32 @snprintf(i8* %26, i32 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %33)
br label %35
35: ; preds = %25, %21
%36 = load i8*, i8** %5
%37 = load i8, i8* %36
store i8 %37, i8* %6
%38 = load i8, i8* %6
%39 = call i64 @isprint(i8 zeroext %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %35
store i8 46, i8* %6
br label %42
42: ; preds = %41, %35
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%44 = load i8*, i8** %5
%45 = load i8, i8* %44
%46 = call i32 @snprintf(i8* %43, i32 4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %45)
%47 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%48 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%49 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
%51 = sext i32 %50 to i64
%52 = sub i64 53, %51
%53 = sub i64 %52, 1
%54 = trunc i64 %53 to i32
%55 = call i32 @strncat(i8* %47, i8* %48, i32 %54)
%56 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%57 = load i8, i8* %6
%58 = call i32 @snprintf(i8* %56, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %57)
%59 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%60 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%61 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%62 = call i32 @strlen(i8* %61)
%63 = sext i32 %62 to i64
%64 = sub i64 21, %63
%65 = sub i64 %64, 1
%66 = trunc i64 %65 to i32
%67 = call i32 @strncat(i8* %59, i8* %60, i32 %66)
%68 = load i32, i32* %7
%69 = srem i32 %68, 16
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %78
71: ; preds = %42
%72 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%73 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%74 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%75 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %72, i8* %73, i8* %74)
%76 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
store i8 0, i8* %76
%77 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
store i8 0, i8* %77
br label %100
78: ; preds = %42
%79 = load i32, i32* %7
%80 = srem i32 %79, 8
%81 = icmp eq i32 %80, 0
br i1 %81, label %82, label %99
82: ; preds = %78
%83 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%84 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%85 = call i32 @strlen(i8* %84)
%86 = sext i32 %85 to i64
%87 = sub i64 53, %86
%88 = sub i64 %87, 1
%89 = trunc i64 %88 to i32
%90 = call i32 @strncat(i8* %83, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %89)
%91 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%92 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%93 = call i32 @strlen(i8* %92)
%94 = sext i32 %93 to i64
%95 = sub i64 21, %94
%96 = sub i64 %95, 1
%97 = trunc i64 %96 to i32
%98 = call i32 @strncat(i8* %91, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 %97)
br label %99
99: ; preds = %82, %78
br label %100
100: ; preds = %99, %71
%101 = load i8*, i8** %5
%102 = getelementptr inbounds i8, i8* %101, i32 1
store i8* %102, i8** %5
br label %103
103: ; preds = %100
%104 = load i32, i32* %7
%105 = add nsw i32 %104, 1
store i32 %105, i32* %7
br label %17
106: ; preds = %17
%107 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%108 = call i32 @strlen(i8* %107)
%109 = icmp sgt i32 %108, 0
br i1 %109, label %110, label %115
110: ; preds = %106
%111 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%112 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%113 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%114 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %111, i8* %112, i8* %113)
br label %115
115: ; preds = %110, %106
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%.4x\00"
@.str.1 = [6 x i8] c"%02X \00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [24 x i8] c"[%4.4s] %-50.50s %s\0A\00"
@.str.4 = [3 x i8] c" \00"
@.str.5 = [2 x i8] c" \00"
define void @hex_dump(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca [10 x i8]
%5 = alloca [53 x i8]
%6 = alloca [21 x i8]
%7 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [53 x i8], [53 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%11 = icmp slt i32 %1, 1
br i1 %11, label %55, label %12
12: ; preds = %2
%13 = ptrtoint i8* %0 to i64
br label %14
14: ; preds = %12, %51
%15 = phi i32 [ 1, %12 ], [ %53, %51 ]
%16 = phi i8* [ %0, %12 ], [ %52, %51 ]
%17 = and i32 %15, 15
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = ptrtoint i8* %16 to i64
%21 = sub i64 %20, %13
%22 = trunc i64 %21 to i8
%23 = call i32 @snprintf(i8* %8, i32 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %22)
br label %24
24: ; preds = %19, %14
%25 = load i8, i8* %16
%26 = call i64 @isprint(i8 zeroext %25)
%27 = icmp eq i64 %26, 0
%28 = select i1 %27, i8 46, i8 %25
%29 = load i8, i8* %16
%30 = call i32 @snprintf(i8* %7, i32 4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %29)
%31 = call i32 @strlen(i8* %9)
%32 = sub i32 52, %31
%33 = call i32 @strncat(i8* %9, i8* %7, i32 %32)
%34 = call i32 @snprintf(i8* %7, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %28)
%35 = call i32 @strlen(i8* %10)
%36 = sub i32 20, %35
%37 = call i32 @strncat(i8* %10, i8* %7, i32 %36)
%38 = icmp eq i32 %17, 0
br i1 %38, label %39, label %41
39: ; preds = %24
%40 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %8, i8* %9, i8* %10)
store i8 0, i8* %9
store i8 0, i8* %10
br label %51
41: ; preds = %24
%42 = and i32 %15, 7
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %51
44: ; preds = %41
%45 = call i32 @strlen(i8* %9)
%46 = sub i32 52, %45
%47 = call i32 @strncat(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %46)
%48 = call i32 @strlen(i8* %10)
%49 = sub i32 20, %48
%50 = call i32 @strncat(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %41, %44, %39
%52 = getelementptr inbounds i8, i8* %16, i64 1
%53 = add nuw i32 %15, 1
%54 = icmp eq i32 %15, %1
br i1 %54, label %55, label %14
55: ; preds = %51, %2
%56 = call i32 @strlen(i8* %9)
%57 = icmp sgt i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %55
%59 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %8, i8* %9, i8* %10)
br label %60
60: ; preds = %58, %55
ret void
}