#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 u_int;
typedef int u_char;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
void mem_dump(FILE *f_output, u_char *pkt, u_int len) {
  u_int x, i = 0, tmp;
  while (i < len) {
    if ((len - i) > 16)
      x = 16;
    else
      x = len - i;
    fprintf(f_output, "%4.4x: ", i);
    for (tmp = 0; tmp < x; tmp++)
      fprintf(f_output, "%2.2x ", pkt[i + tmp]);
    for (tmp = x; tmp < 16; tmp++)
      fprintf(f_output, "   ");
    for (tmp = 0; tmp < x; tmp++) {
      char c = pkt[i + tmp];
      if (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')) ||
          ((c >= '0') && (c <= '9')))
        fprintf(f_output, "%c", c);
      else
        fputs(".", f_output);
    }
    i += x;
    fprintf(f_output, "\n");
  }
  fprintf(f_output, "\n");
  fflush(f_output);
}


x86 assembly (clang, -O0):
<mem_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12d4 <mem_dump+0x1a4>
mov    -0x14(%rbp),%eax
sub    -0x1c(%rbp),%eax
cmp    $0x10,%eax
jle    1171 <mem_dump+0x41>
movl   $0x10,-0x18(%rbp)
jmp    117a <mem_dump+0x4a>
mov    -0x14(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11d2 <mem_dump+0xa2>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1196 <mem_dump+0x66>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x10,-0x20(%rbp)
jge    1202 <mem_dump+0xd2>
mov    -0x8(%rbp),%rdi
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11d8 <mem_dump+0xa8>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12b4 <mem_dump+0x184>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0x41,%eax
jl     1242 <mem_dump+0x112>
movsbl -0x21(%rbp),%eax
cmp    $0x5a,%eax
jle    1276 <mem_dump+0x146>
movsbl -0x21(%rbp),%eax
cmp    $0x61,%eax
jl     125c <mem_dump+0x12c>
movsbl -0x21(%rbp),%eax
cmp    $0x7a,%eax
jle    1276 <mem_dump+0x146>
movsbl -0x21(%rbp),%eax
cmp    $0x30,%eax
jl     1291 <mem_dump+0x161>
movsbl -0x21(%rbp),%eax
cmp    $0x39,%eax
jg     1291 <mem_dump+0x161>
mov    -0x8(%rbp),%rdi
movsbl -0x21(%rbp),%edx
lea    0xd8e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    12a1 <mem_dump+0x171>
mov    -0x8(%rbp),%rsi
lea    0xd7a(%rip),%rdi
call   1030 <fputs@plt>
jmp    12a6 <mem_dump+0x176>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1209 <mem_dump+0xd9>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xd50(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    114a <mem_dump+0x1a>
mov    -0x8(%rbp),%rdi
lea    0xd39(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fflush@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,0x8(%rsp)
mov    %rdi,%r13
test   %edx,%edx
jle    12d9 <mem_dump+0x199>
mov    %edx,%r12d
mov    $0x10,%eax
sub    %edx,%eax
mov    %rax,0x18(%rsp)
lea    0xe94(%rip),%r15
xor    %r14d,%r14d
mov    %edx,0x4(%rsp)
jmp    119f <mem_dump+0x5f>
nopl   (%rax)
add    (%rsp),%r14d
mov    $0xa,%edi
mov    %r13,%rsi
call   1030 <fputc@plt>
mov    0x4(%rsp),%r12d
cmp    %r12d,%r14d
jge    12d9 <mem_dump+0x199>
sub    %r14d,%r12d
cmp    $0x10,%r12d
mov    $0x10,%eax
cmovl  %r12d,%eax
mov    %eax,(%rsp)
mov    %r13,%rdi
lea    0xe44(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r14,0x20(%rsp)
movslq %r14d,%rax
mov    %rax,0x10(%rsp)
test   %r12d,%r12d
jle    121b <mem_dump+0xdb>
mov    (%rsp),%eax
cmp    $0x2,%eax
mov    $0x1,%ebx
cmovge %eax,%ebx
mov    0x8(%rsp),%rax
mov    0x10(%rsp),%rcx
lea    (%rax,%rcx,4),%rbp
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp,%r14,4),%edx
mov    %r13,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%r14
cmp    %r14,%rbx
jne    1200 <mem_dump+0xc0>
cmp    $0xf,%r12d
lea    0xde9(%rip),%rbp
mov    0x20(%rsp),%r14
jg     125a <mem_dump+0x11a>
mov    0x18(%rsp),%rax
lea    (%rax,%r14,1),%ebx
cs nopw 0x0(%rax,%rax,1)
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %r13,%rcx
call   1060 <fwrite@plt>
add    $0xffffffff,%ebx
jne    1240 <mem_dump+0x100>
test   %r12d,%r12d
jle    1180 <mem_dump+0x40>
mov    (%rsp),%eax
cmp    $0x2,%eax
mov    $0x1,%ebp
cmovge %eax,%ebp
mov    0x8(%rsp),%rax
mov    0x10(%rsp),%rcx
lea    (%rax,%rcx,4),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r12,%rbx,4),%eax
movsbl %al,%ecx
shl    $0x18,%eax
mov    %eax,%edx
and    $0xdf000000,%edx
add    $0xbfffffff,%edx
add    $0xd0ffffff,%eax
cmp    $0xaffffff,%eax
mov    $0x2e,%edi
cmovb  %ecx,%edi
cmp    $0x1affffff,%edx
cmovb  %ecx,%edi
mov    %r13,%rsi
call   1030 <fputc@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1290 <mem_dump+0x150>
jmp    1180 <mem_dump+0x40>
mov    $0xa,%edi
mov    %r13,%rsi
call   1030 <fputc@plt>
mov    %r13,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fflush@plt>

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

LLVM IR (-O2):
@.str = [8 x i8] c"%4.4x: \00"
@.str.1 = [7 x i8] c"%2.2x \00"
@.str.2 = [4 x i8] c" \00"
define void @mem_dump(i32* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %56
5: ; preds = %3, %52
%6 = phi i32 [ %53, %52 ], [ 0, %3 ]
%7 = sub nsw i32 %2, %6
%8 = icmp slt i32 %7, 16
%9 = select i1 %8, i32 %7, i32 16
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %6)
%11 = icmp sgt i32 %7, 0
br i1 %11, label %12, label %16
12: ; preds = %5
%13 = sext i32 %6 to i64
%14 = call i32 @llvm.smax.i32(i32 %9, i32 1)
%15 = zext i32 %14 to i64
br label %17
16: ; preds = %17, %5
br i1 %8, label %30, label %25
17: ; preds = %12, %17
%18 = phi i64 [ 0, %12 ], [ %23, %17 ]
%19 = add nsw i64 %18, %13
%20 = getelementptr inbounds i32, i32* %1, i64 %19
%21 = load i32, i32* %20
%22 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = add nuw nsw i64 %18, 1
%24 = icmp eq i64 %23, %15
br i1 %24, label %16, label %17
25: ; preds = %30, %16
br i1 %11, label %26, label %52
26: ; preds = %25
%27 = sext i32 %6 to i64
%28 = call i32 @llvm.smax.i32(i32 %9, i32 1)
%29 = zext i32 %28 to i64
br label %35
30: ; preds = %16, %30
%31 = phi i32 [ %33, %30 ], [ %7, %16 ]
%32 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 3, i64 1, i32* %0)
%33 = add i32 %31, 1
%34 = icmp eq i32 %33, 16
br i1 %34, label %25, label %30
35: ; preds = %26, %35
%36 = phi i64 [ 0, %26 ], [ %50, %35 ]
%37 = add nsw i64 %36, %27
%38 = getelementptr inbounds i32, i32* %1, i64 %37
%39 = load i32, i32* %38
%40 = shl i32 %39, 24
%41 = and i32 %40, -553648128
%42 = add i32 %41, -1073741825
%43 = icmp ult i32 %42, 452984831
%44 = add i32 %40, -788529153
%45 = icmp ult i32 %44, 184549375
%46 = select i1 %43, i1 true, i1 %45
%47 = ashr exact i32 %40, 24
%48 = select i1 %46, i32 %47, i32 46
%49 = tail call i32 @fputc(i32 %48, i32* %0)
%50 = add nuw nsw i64 %36, 1
%51 = icmp eq i64 %50, %29
br i1 %51, label %52, label %35
52: ; preds = %35, %25
%53 = add nsw i32 %9, %6
%54 = tail call i32 @fputc(i32 10, i32* %0)
%55 = icmp slt i32 %53, %2
br i1 %55, label %5, label %56
56: ; preds = %52, %3
%57 = tail call i32 @fputc(i32 10, i32* %0)
%58 = tail call i32 @fflush(i32* %0)
ret void
}