#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputc(unsigned char const, int /*<<< orphan*/ *);
void dump_packet(FILE *file, const unsigned char *data, size_t length) {
  size_t y;
  for (y = 0; y < length; y += 0x10, data += 0x10) {
    size_t x, columns = length - y;
    if (columns > 0x10)
      columns = 0x10;
    fprintf(file, "%08lx   ", (unsigned long)y);
    for (x = 0; x < columns; x++) {
      if (x == 0x08)
        fprintf(file, " ");
      fprintf(file, "%02x ", data[x]);
    }
    for (; x < 0x10; x++) {
      if (x == 0x08)
        fprintf(file, " ");
      fprintf(file, "   ");
    }
    fprintf(file, " ");
    for (x = 0; x < columns; x++)
      fputc(data[x] >= 0x20 && data[x] < 0x80 ? data[x] : '.', file);
    fprintf(file, "\n");
  }
}


x86 assembly (clang, -O0):
<dump_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    12f5 <dump_packet+0x1d5>
mov    -0x18(%rbp),%rax
sub    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x10,-0x30(%rbp)
jbe    1169 <dump_packet+0x49>
movq   $0x10,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe88(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    11e1 <dump_packet+0xc1>
cmpq   $0x8,-0x28(%rbp)
jne    11b2 <dump_packet+0x92>
mov    -0x8(%rbp),%rdi
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1187 <dump_packet+0x67>
jmp    11e6 <dump_packet+0xc6>
cmpq   $0x10,-0x28(%rbp)
jae    1231 <dump_packet+0x111>
cmpq   $0x8,-0x28(%rbp)
jne    120e <dump_packet+0xee>
mov    -0x8(%rbp),%rdi
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xdec(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11e6 <dump_packet+0xc6>
mov    -0x8(%rbp),%rdi
lea    0xdcb(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    12c6 <dump_packet+0x1a6>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     1299 <dump_packet+0x179>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x80,%eax
jge    1299 <dump_packet+0x179>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x34(%rbp)
jmp    12a6 <dump_packet+0x186>
mov    $0x2e,%eax
mov    %eax,-0x34(%rbp)
jmp    12a6 <dump_packet+0x186>
mov    -0x34(%rbp),%eax
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1030 <fputc@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    124b <dump_packet+0x12b>
mov    -0x8(%rbp),%rdi
lea    0xd3e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x10(%rbp)
jmp    113c <dump_packet+0x1c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_packet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %rdx,%rdx
je     12b4 <dump_packet+0x184>
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xeb1(%rip),%r13
mov    %rdx,%rbp
xor    %r14d,%r14d
mov    %rdx,(%rsp)
jmp    1190 <dump_packet+0x60>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
mov    0x8(%rsp),%r14
add    $0x10,%r14
add    $0x10,%r15
mov    0x10(%rsp),%rbp
add    $0xfffffffffffffff0,%rbp
mov    (%rsp),%rdx
cmp    %rdx,%r14
jae    12b4 <dump_packet+0x184>
cmp    $0x10,%rbp
mov    $0x10,%r12d
cmovb  %rbp,%r12
mov    %rbx,%rdi
lea    0xe58(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rsp),%rax
cmp    %rax,%r14
mov    %rbp,0x10(%rsp)
mov    %r14,0x8(%rsp)
jne    11d0 <dump_packet+0xa0>
xor    %eax,%eax
jmp    1230 <dump_packet+0x100>
nopl   0x0(%rax)
mov    %r12,%rbp
xor    %r14d,%r14d
jmp    11ff <dump_packet+0xcf>
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%r14,1),%edx
mov    %rbx,%rdi
lea    0xe1a(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%r14
cmp    %r14,%r12
je     1220 <dump_packet+0xf0>
cmp    $0x8,%r14
jne    11e0 <dump_packet+0xb0>
mov    $0x20,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
jmp    11e0 <dump_packet+0xb0>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpq   $0xf,0x10(%rsp)
mov    0x8(%rsp),%r14
mov    %rbp,%rax
ja     1270 <dump_packet+0x140>
mov    $0x10,%ebp
sub    %rax,%rbp
jmp    125b <dump_packet+0x12b>
nopw   0x0(%rax,%rax,1)
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r13,%rdi
mov    %rbx,%rcx
call   1050 <fwrite@plt>
add    $0xffffffffffffffff,%rbp
je     1270 <dump_packet+0x140>
cmp    $0x8,%rbp
jne    1240 <dump_packet+0x110>
mov    $0x20,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
jmp    1240 <dump_packet+0x110>
mov    $0x20,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
cmp    (%rsp),%r14
mov    $0x2e,%r14d
je     1160 <dump_packet+0x30>
xor    %ebp,%ebp
nop
movzbl (%r15,%rbp,1),%eax
cmp    $0x20,%al
cmovl  %r14d,%eax
movzbl %al,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1290 <dump_packet+0x160>
jmp    1160 <dump_packet+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [9 x i8] c"%08lx \00"
@.str.2 = [6 x i8] c"%02x \00"
@.str.3 = [4 x i8] c" \00"
define void @dump_packet(i32* %0, i8* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %54, label %5
5: ; preds = %3, %48
%6 = phi i64 [ %53, %48 ], [ %2, %3 ]
%7 = phi i64 [ %50, %48 ], [ 0, %3 ]
%8 = phi i8* [ %51, %48 ], [ %1, %3 ]
%9 = call i64 @llvm.umin.i64(i64 %6, i64 16)
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %7)
%11 = icmp eq i64 %7, %2
br i1 %11, label %14, label %16
12: ; preds = %21
%13 = icmp ult i64 %6, 16
br i1 %13, label %14, label %37
14: ; preds = %5, %12
%15 = phi i64 [ 0, %5 ], [ %9, %12 ]
br label %28
16: ; preds = %5, %21
%17 = phi i64 [ %26, %21 ], [ 0, %5 ]
%18 = icmp eq i64 %17, 8
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 bitcast (i32 (i8, i32*)* @fputc to i32 (i32, i32*)*)(i32 32, i32* %0)
br label %21
21: ; preds = %19, %16
%22 = getelementptr inbounds i8, i8* %8, i64 %17
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = add nuw nsw i64 %17, 1
%27 = icmp eq i64 %26, %9
br i1 %27, label %12, label %16
28: ; preds = %14, %33
%29 = phi i64 [ %35, %33 ], [ %15, %14 ]
%30 = icmp eq i64 %29, 8
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = tail call i32 bitcast (i32 (i8, i32*)* @fputc to i32 (i32, i32*)*)(i32 32, i32* %0)
br label %33
33: ; preds = %31, %28
%34 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 3, i64 1, i32* %0)
%35 = add nuw nsw i64 %29, 1
%36 = icmp eq i64 %35, 16
br i1 %36, label %37, label %28
37: ; preds = %33, %12
%38 = tail call i32 bitcast (i32 (i8, i32*)* @fputc to i32 (i32, i32*)*)(i32 32, i32* %0)
br i1 %11, label %48, label %39
39: ; preds = %37, %39
%40 = phi i64 [ %46, %39 ], [ 0, %37 ]
%41 = getelementptr inbounds i8, i8* %8, i64 %40
%42 = load i8, i8* %41
%43 = icmp sgt i8 %42, 31
%44 = select i1 %43, i8 %42, i8 46
%45 = tail call i32 @fputc(i8 zeroext %44, i32* %0)
%46 = add nuw nsw i64 %40, 1
%47 = icmp eq i64 %46, %9
br i1 %47, label %48, label %39
48: ; preds = %39, %37
%49 = tail call i32 bitcast (i32 (i8, i32*)* @fputc to i32 (i32, i32*)*)(i32 10, i32* %0)
%50 = add i64 %7, 16
%51 = getelementptr inbounds i8, i8* %8, i64 16
%52 = icmp ult i64 %50, %2
%53 = add i64 %6, -16
br i1 %52, label %5, label %54
54: ; preds = %48, %3
ret void
}