#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__ isalnum(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 hexdump(void *data, int size) {
  unsigned char *p = 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)p - (unsigned int)data));
    }
    c = *p;
    if (isalnum(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, "\t", sizeof(hexstr) - strlen(hexstr) - 1);
      strncat(charstr, "\t", sizeof(charstr) - strlen(charstr) - 1);
    }
    p++;
  }
  if (strlen(hexstr) > 0) {
    printf("[%4.4s]   %-50.50s  %s\n", addrstr, hexstr, charstr);
  }
}


x86 assembly (clang, -O0):
<hexdump>:
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   1070 <memset@plt>
lea    -0x2e(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <memset@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x35,%edx
call   1070 <memset@plt>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x15,%edx
call   1070 <memset@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     13cf <hexdump+0x26f>
mov    -0x20(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1206 <hexdump+0xa6>
lea    -0x2e(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %ecx,%eax
mov    $0xa,%esi
lea    0xe02(%rip),%rdx
movzbl %al,%ecx
call   1060 <snprintf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%edi
call   1050 <isalnum@plt>
cmp    $0x0,%rax
jne    1226 <hexdump+0xc6>
movb   $0x2e,-0x19(%rbp)
lea    -0x24(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    $0x4,%esi
lea    0xdcb(%rip),%rdx
movzbl (%rax),%ecx
call   1060 <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   1080 <strncat@plt>
lea    -0x24(%rbp),%rdi
mov    $0x4,%esi
lea    0xd76(%rip),%rdx
movzbl -0x19(%rbp),%ecx
call   1060 <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   1080 <strncat@plt>
mov    -0x20(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1326 <hexdump+0x1c6>
lea    -0x2e(%rbp),%rsi
lea    -0x70(%rbp),%rdx
lea    -0x90(%rbp),%rcx
lea    0xcfd(%rip),%rdi
call   1040 <printf@plt>
movb   $0x0,-0x70(%rbp)
movb   $0x0,-0x90(%rbp)
jmp    13b5 <hexdump+0x255>
mov    -0x20(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    13b0 <hexdump+0x250>
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    0xcb9(%rip),%rsi
call   1080 <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   1080 <strncat@plt>
jmp    13b5 <hexdump+0x255>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c4 <hexdump+0x64>
lea    -0x70(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jle    13fc <hexdump+0x29c>
lea    -0x2e(%rbp),%rsi
lea    -0x70(%rbp),%rdx
lea    -0x90(%rbp),%rcx
lea    0xc17(%rip),%rdi
call   1040 <printf@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
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    12fa <hexdump+0x1aa>
mov    %esi,%eax
mov    %rax,0x10(%rsp)
xor    %r15d,%r15d
lea    0x40(%rsp),%r13
jmp    11ea <hexdump+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     12fa <hexdump+0x1aa>
mov    %r13,%rbx
mov    %r15,%r14
add    $0x1,%r15
mov    %r15d,%ebp
and    $0xf,%ebp
cmp    $0x1,%ebp
jne    1217 <hexdump+0xc7>
movzbl %r14b,%ecx
mov    %rsp,%rdi
mov    $0xa,%esi
lea    0xdee(%rip),%rdx
call   1060 <snprintf@plt>
mov    0x18(%rsp),%r13
movzbl 0x0(%r13,%r14,1),%r12d
mov    %r12d,%edi
call   1050 <isalnum@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   1060 <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   1070 <strncat@plt>
mov    %r14,%rdi
mov    $0x4,%esi
lea    0xd8a(%rip),%rdx
mov    %r12d,%ecx
call   1060 <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   1070 <strncat@plt>
test   %ebp,%ebp
je     11c0 <hexdump+0x70>
test   $0x7,%r15b
jne    11df <hexdump+0x8f>
mov    %r13,%rdi
call   1030 <strlen@plt>
mov    $0x34,%edx
sub    %eax,%edx
mov    %r13,%rdi
lea    0xd53(%rip),%rbp
mov    %rbp,%rsi
call   1070 <strncat@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    $0x14,%edx
sub    %eax,%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <strncat@plt>
jmp    11df <hexdump+0x8f>
lea    0x40(%rsp),%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1321 <hexdump+0x1d1>
lea    0xcff(%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 = [2 x i8] c"\09\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 [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 = %102, %2
%18 = load i32, i32* %7
%19 = load i32, i32* %4
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %105
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 %34
25: ; preds = %21
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%27 = load i8*, i8** %5
%28 = ptrtoint i8* %27 to i32
%29 = load i8*, i8** %3
%30 = ptrtoint i8* %29 to i32
%31 = sub i32 %28, %30
%32 = trunc i32 %31 to i8
%33 = call i32 @snprintf(i8* %26, i32 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %32)
br label %34
34: ; preds = %25, %21
%35 = load i8*, i8** %5
%36 = load i8, i8* %35
store i8 %36, i8* %6
%37 = load i8, i8* %6
%38 = call i64 @isalnum(i8 zeroext %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %34
store i8 46, i8* %6
br label %41
41: ; preds = %40, %34
%42 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%43 = load i8*, i8** %5
%44 = load i8, i8* %43
%45 = call i32 @snprintf(i8* %42, i32 4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %44)
%46 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%47 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%48 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%49 = call i32 @strlen(i8* %48)
%50 = sext i32 %49 to i64
%51 = sub i64 53, %50
%52 = sub i64 %51, 1
%53 = trunc i64 %52 to i32
%54 = call i32 @strncat(i8* %46, i8* %47, i32 %53)
%55 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%56 = load i8, i8* %6
%57 = call i32 @snprintf(i8* %55, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %56)
%58 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%59 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%60 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%61 = call i32 @strlen(i8* %60)
%62 = sext i32 %61 to i64
%63 = sub i64 21, %62
%64 = sub i64 %63, 1
%65 = trunc i64 %64 to i32
%66 = call i32 @strncat(i8* %58, i8* %59, i32 %65)
%67 = load i32, i32* %7
%68 = srem i32 %67, 16
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %77
70: ; preds = %41
%71 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%72 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%73 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%74 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %71, i8* %72, i8* %73)
%75 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
store i8 0, i8* %75
%76 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
store i8 0, i8* %76
br label %99
77: ; preds = %41
%78 = load i32, i32* %7
%79 = srem i32 %78, 8
%80 = icmp eq i32 %79, 0
br i1 %80, label %81, label %98
81: ; preds = %77
%82 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%83 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%84 = call i32 @strlen(i8* %83)
%85 = sext i32 %84 to i64
%86 = sub i64 53, %85
%87 = sub i64 %86, 1
%88 = trunc i64 %87 to i32
%89 = call i32 @strncat(i8* %82, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 %88)
%90 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%91 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%92 = call i32 @strlen(i8* %91)
%93 = sext i32 %92 to i64
%94 = sub i64 21, %93
%95 = sub i64 %94, 1
%96 = trunc i64 %95 to i32
%97 = call i32 @strncat(i8* %90, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 %96)
br label %98
98: ; preds = %81, %77
br label %99
99: ; preds = %98, %70
%100 = load i8*, i8** %5
%101 = getelementptr inbounds i8, i8* %100, i32 1
store i8* %101, i8** %5
br label %102
102: ; preds = %99
%103 = load i32, i32* %7
%104 = add nsw i32 %103, 1
store i32 %104, i32* %7
br label %17
105: ; preds = %17
%106 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%107 = call i32 @strlen(i8* %106)
%108 = icmp sgt i32 %107, 0
br i1 %108, label %109, label %114
109: ; preds = %105
%110 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%111 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%112 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%113 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %110, i8* %111, i8* %112)
br label %114
114: ; preds = %109, %105
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 = [2 x i8] c"\09\00"
define void @hexdump(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 %56, label %12
12: ; preds = %2
%13 = ptrtoint i8* %0 to i64
%14 = trunc i64 %13 to i8
br label %15
15: ; preds = %12, %52
%16 = phi i32 [ 1, %12 ], [ %54, %52 ]
%17 = phi i8* [ %0, %12 ], [ %53, %52 ]
%18 = and i32 %16, 15
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = ptrtoint i8* %17 to i64
%22 = trunc i64 %21 to i8
%23 = sub i8 %22, %14
%24 = call i32 @snprintf(i8* %8, i32 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %23)
br label %25
25: ; preds = %20, %15
%26 = load i8, i8* %17
%27 = call i64 @isalnum(i8 zeroext %26)
%28 = icmp eq i64 %27, 0
%29 = select i1 %28, i8 46, i8 %26
%30 = load i8, i8* %17
%31 = call i32 @snprintf(i8* %7, i32 4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %30)
%32 = call i32 @strlen(i8* %9)
%33 = sub i32 52, %32
%34 = call i32 @strncat(i8* %9, i8* %7, i32 %33)
%35 = call i32 @snprintf(i8* %7, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %29)
%36 = call i32 @strlen(i8* %10)
%37 = sub i32 20, %36
%38 = call i32 @strncat(i8* %10, i8* %7, i32 %37)
%39 = icmp eq i32 %18, 0
br i1 %39, label %40, label %42
40: ; preds = %25
%41 = 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 %52
42: ; preds = %25
%43 = and i32 %16, 7
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %52
45: ; preds = %42
%46 = call i32 @strlen(i8* %9)
%47 = sub i32 52, %46
%48 = call i32 @strncat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 %47)
%49 = call i32 @strlen(i8* %10)
%50 = sub i32 20, %49
%51 = call i32 @strncat(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %42, %45, %40
%53 = getelementptr inbounds i8, i8* %17, i64 1
%54 = add nuw i32 %16, 1
%55 = icmp eq i32 %16, %1
br i1 %55, label %56, label %15
56: ; preds = %52, %2
%57 = call i32 @strlen(i8* %9)
%58 = icmp sgt i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = 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 %61
61: ; preds = %59, %56
ret void
}