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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void packet_hexdump(const uint8_t *data, size_t size) {
  size_t i;
  printf("%02x:", data[0]);
  for (i = 1; i < size; i++) {
    printf("%02x:", data[i]);
    if ((i & 0xf) == 0xf) {
      printf("\n");
    }
  }
  printf("\n\n");
}


x86 assembly (clang, -O0):
<packet_hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1199 <packet_hexdump+0x89>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
and    $0xf,%rax
cmp    $0xf,%rax
jne    1183 <packet_hexdump+0x73>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1188 <packet_hexdump+0x78>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113c <packet_hexdump+0x2c>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<packet_hexdump>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
mov    (%rdi),%esi
lea    0xeb9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x2,%r14
jb     119b <packet_hexdump+0x6b>
mov    $0x1,%ebx
lea    0xea0(%rip),%r15
jmp    1179 <packet_hexdump+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%r14
je     119b <packet_hexdump+0x6b>
mov    (%r12,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
not    %eax
test   $0xf,%al
jne    1170 <packet_hexdump+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1170 <packet_hexdump+0x40>
lea    0xe64(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <puts@plt>

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

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