#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void dump_packet(unsigned char *buf, int len) {
  int i;
  printf("[");
  for (i = 0; i < len; i++) {
    printf(" %02x", buf[i]);
    if ((i + 1) % 16 == 0)
      printf("\n ");
    else if ((i + 1) % 8 == 0)
      printf(" ");
  }
  printf(" ]\n");
}


x86 assembly (clang, -O0):
<dump_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c1 <dump_packet+0xb1>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1184 <dump_packet+0x74>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ae <dump_packet+0x9e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11a9 <dump_packet+0x99>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ae <dump_packet+0x9e>
jmp    11b3 <dump_packet+0xa3>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1134 <dump_packet+0x24>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_packet>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r12
mov    $0x5b,%edi
call   1030 <putchar@plt>
test   %ebp,%ebp
jle    1198 <dump_packet+0x68>
mov    %ebp,%ebp
lea    0xeac(%rip),%r14
lea    0xeab(%rip),%r15
xor    %ebx,%ebx
jmp    116f <dump_packet+0x3f>
nop
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %rbx,%rbp
je     1198 <dump_packet+0x68>
movzbl (%r12,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
test   $0xf,%bl
je     1160 <dump_packet+0x30>
test   $0x7,%bl
jne    116a <dump_packet+0x3a>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    116a <dump_packet+0x3a>
lea    0xe6a(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>

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

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