#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 hex_dump(const unsigned char *packet, size_t size) {
  unsigned char *byte = (unsigned char *)packet;
  int count = 0;
  printf("\t\t");
  for (; byte < ((unsigned char *)packet) + size; byte++) {
    count++;
    printf("%02x ", *byte);
    if (count % 16 == 0)
      printf("\n\t\t");
  }
  printf("\n\n");
}


x86 assembly (clang, -O0):
<hex_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
add    -0x10(%rbp),%rcx
cmp    %rcx,%rax
jae    11a8 <hex_dump+0x98>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%esi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1192 <hex_dump+0x82>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1197 <hex_dump+0x87>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113d <hex_dump+0x2d>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_dump>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xed2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14,%r14
jle    118b <hex_dump+0x6b>
add    %rbx,%r14
mov    $0x1,%ebp
lea    0xeb0(%rip),%r15
lea    0xeaf(%rip),%r12
jmp    116c <hex_dump+0x4c>
nopl   0x0(%rax)
add    $0x1,%rbx
add    $0x1,%ebp
cmp    %r14,%rbx
jae    118b <hex_dump+0x6b>
movzbl (%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0xf,%bpl
jne    1160 <hex_dump+0x40>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1160 <hex_dump+0x40>
lea    0xe78(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c"\09\09\00"
@.str.1 = [6 x i8] c"%02x \00"
@.str.2 = [4 x i8] c"\0A\09\09\00"
@str = [2 x i8] c"\0A\00"
define void @hex_dump(i8* %0, i64 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds i8, i8* %0, i64 %1
%5 = icmp sgt i64 %1, 0
br i1 %5, label %6, label %20
6: ; preds = %2, %17
%7 = phi i32 [ %9, %17 ], [ 0, %2 ]
%8 = phi i8* [ %18, %17 ], [ %0, %2 ]
%9 = add nuw nsw i32 %7, 1
%10 = load i8, i8* %8
%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 = and i32 %9, 15
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %6
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %6, %15
%18 = getelementptr inbounds i8, i8* %8, i64 1
%19 = icmp ult i8* %18, %4
br i1 %19, label %6, label %20
20: ; preds = %17, %2
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
}