#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void pkt_dump(const char *buf, uint32_t size) {
  printf("Packet (%dB):", size);
  uint32_t i = 0;
  for (i = 0; i < size; ++i) {
    if (i == 0 || i % 8 == 0) {
      if (i == 160) {
        printf("\n ...");
        break;
      }
      printf("\n%4d | ", i);
    }
    printf("0x%02x ", (unsigned char)*(buf + i));
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<pkt_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c1 <pkt_dump+0xb1>
cmpl   $0x0,-0x10(%rbp)
je     1168 <pkt_dump+0x58>
mov    -0x10(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1199 <pkt_dump+0x89>
cmpl   $0xa0,-0x10(%rbp)
jne    1188 <pkt_dump+0x78>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c1 <pkt_dump+0xb1>
mov    -0x10(%rbp),%esi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113e <pkt_dump+0x2e>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pkt_dump>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r12
lea    0xecb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
jle    11a2 <pkt_dump+0x82>
mov    %ebx,%r13d
lea    0xeca(%rip),%r14
lea    0xecb(%rip),%r15
xor    %ebx,%ebx
jmp    1178 <pkt_dump+0x58>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
je     11a2 <pkt_dump+0x82>
test   $0x7,%bl
jne    1160 <pkt_dump+0x40>
cmp    $0xa0,%rbx
je     1194 <pkt_dump+0x74>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1160 <pkt_dump+0x40>
lea    0xe73(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"Packet (%dB):\00"
@.str.1 = [6 x i8] c"\0A ...\00"
@.str.2 = [8 x i8] c"\0A%4d | \00"
@.str.3 = [8 x i8] c"0x%02x \00"
@.str.4 = [2 x i8] c"\0A\00"
define void @pkt_dump(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 0, i32* %5
store i32 0, i32* %5
br label %8
8: ; preds = %35, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %38
12: ; preds = %8
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = load i32, i32* %5
%17 = srem i32 %16, 8
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %15, %12
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, 160
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %38
24: ; preds = %19
%25 = load i32, i32* %5
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %24, %15
%28 = load i8*, i8** %3
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %27
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %8
38: ; preds = %22, %8
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"Packet (%dB):\00"
@.str.1 = [6 x i8] c"\0A ...\00"
@.str.2 = [8 x i8] c"\0A%4d | \00"
@.str.3 = [8 x i8] c"0x%02x \00"
define void @pkt_dump(i8* nocapture %0, i32 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %1)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %25
5: ; preds = %2
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %18
%8 = phi i64 [ 0, %5 ], [ %23, %18 ]
%9 = trunc i64 %8 to i32
%10 = and i32 %9, 7
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %7
%13 = icmp eq i64 %8, 160
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %25
16: ; preds = %12
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %9)
br label %18
18: ; preds = %7, %16
%19 = getelementptr inbounds i8, i8* %0, i64 %8
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = add nuw nsw i64 %8, 1
%24 = icmp eq i64 %23, %6
br i1 %24, label %25, label %7
25: ; preds = %18, %2, %14
%26 = tail call i32 @putchar(i32 10)
ret void
}