#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 dump_packet(unsigned char *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)(intptr_t)p - (unsigned int)(intptr_t)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, "  ", 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):
<dump_packet>:
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 <dump_packet+0x26f>
mov    -0x20(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1206 <dump_packet+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 <dump_packet+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 <dump_packet+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 <dump_packet+0x255>
mov    -0x20(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    13b0 <dump_packet+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    0xc7c(%rip),%rsi
call   1080 <strncat@plt>
jmp    13b5 <dump_packet+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 <dump_packet+0x64>
lea    -0x70(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jle    13fc <dump_packet+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):
<dump_packet>:
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 <dump_packet+0x1ab>
mov    %esi,%eax
mov    %rax,0x10(%rsp)
xor    %r15d,%r15d
lea    0x40(%rsp),%r13
jmp    11ea <dump_packet+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 <dump_packet+0x1ab>
mov    %r13,%rbx
mov    %r15,%r14
add    $0x1,%r15
mov    %r15d,%ebp
and    $0xf,%ebp
cmp    $0x1,%ebp
jne    1217 <dump_packet+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 <dump_packet+0x70>
test   $0x7,%r15b
jne    11df <dump_packet+0x8f>
mov    %r13,%rdi
call   1030 <strlen@plt>
mov    $0x34,%edx
sub    %eax,%edx
mov    %r13,%rdi
lea    0xd53(%rip),%rsi
call   1070 <strncat@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    $0x14,%edx
sub    %eax,%edx
mov    %rbx,%rdi
lea    0xd36(%rip),%rsi
call   1070 <strncat@plt>
jmp    11df <dump_packet+0x8f>
lea    0x40(%rsp),%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1322 <dump_packet+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 @dump_packet(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 = %104, %2
%18 = load i32, i32* %7
%19 = load i32, i32* %4
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %107
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 %36
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 i64
%29 = trunc i64 %28 to i32
%30 = load i8*, i8** %3
%31 = ptrtoint i8* %30 to i64
%32 = trunc i64 %31 to i32
%33 = sub i32 %29, %32
%34 = trunc i32 %33 to i8
%35 = call i32 @snprintf(i8* %26, i32 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %34)
br label %36
36: ; preds = %25, %21
%37 = load i8*, i8** %5
%38 = load i8, i8* %37
store i8 %38, i8* %6
%39 = load i8, i8* %6
%40 = call i64 @isalnum(i8 zeroext %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %36
store i8 46, i8* %6
br label %43
43: ; preds = %42, %36
%44 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%45 = load i8*, i8** %5
%46 = load i8, i8* %45
%47 = call i32 @snprintf(i8* %44, i32 4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %46)
%48 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%49 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%50 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%51 = call i32 @strlen(i8* %50)
%52 = sext i32 %51 to i64
%53 = sub i64 53, %52
%54 = sub i64 %53, 1
%55 = trunc i64 %54 to i32
%56 = call i32 @strncat(i8* %48, i8* %49, i32 %55)
%57 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%58 = load i8, i8* %6
%59 = call i32 @snprintf(i8* %57, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %58)
%60 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%61 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%62 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%63 = call i32 @strlen(i8* %62)
%64 = sext i32 %63 to i64
%65 = sub i64 21, %64
%66 = sub i64 %65, 1
%67 = trunc i64 %66 to i32
%68 = call i32 @strncat(i8* %60, i8* %61, i32 %67)
%69 = load i32, i32* %7
%70 = srem i32 %69, 16
%71 = icmp eq i32 %70, 0
br i1 %71, label %72, label %79
72: ; preds = %43
%73 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%74 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%75 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%76 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %73, i8* %74, i8* %75)
%77 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
store i8 0, i8* %77
%78 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
store i8 0, i8* %78
br label %101
79: ; preds = %43
%80 = load i32, i32* %7
%81 = srem i32 %80, 8
%82 = icmp eq i32 %81, 0
br i1 %82, label %83, label %100
83: ; preds = %79
%84 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%85 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%86 = call i32 @strlen(i8* %85)
%87 = sext i32 %86 to i64
%88 = sub i64 53, %87
%89 = sub i64 %88, 1
%90 = trunc i64 %89 to i32
%91 = call i32 @strncat(i8* %84, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %90)
%92 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%93 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%94 = call i32 @strlen(i8* %93)
%95 = sext i32 %94 to i64
%96 = sub i64 21, %95
%97 = sub i64 %96, 1
%98 = trunc i64 %97 to i32
%99 = call i32 @strncat(i8* %92, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 %98)
br label %100
100: ; preds = %83, %79
br label %101
101: ; preds = %100, %72
%102 = load i8*, i8** %5
%103 = getelementptr inbounds i8, i8* %102, i32 1
store i8* %103, i8** %5
br label %104
104: ; preds = %101
%105 = load i32, i32* %7
%106 = add nsw i32 %105, 1
store i32 %106, i32* %7
br label %17
107: ; preds = %17
%108 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%109 = call i32 @strlen(i8* %108)
%110 = icmp sgt i32 %109, 0
br i1 %110, label %111, label %116
111: ; preds = %107
%112 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%113 = getelementptr inbounds [53 x i8], [53 x i8]* %10, i64 0, i64 0
%114 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%115 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %112, i8* %113, i8* %114)
br label %116
116: ; preds = %111, %107
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 @dump_packet(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 ([3 x i8], [3 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.5, 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
}