#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 print_packet(char *cbuf, unsigned long length) {
  unsigned char *buf = (unsigned char *)cbuf;
  unsigned char first;
  unsigned char second;
  for (int i = 0; i < length; ++i) {
    first = buf[i] / 16;
    second = buf[i] % 16;
    printf("%x%x ", (unsigned char)first, second);
  }
  printf("\n\n");
}


x86 assembly (clang, -O0):
<print_packet>:
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,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1191 <print_packet+0x81>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x1a(%rbp)
movzbl -0x19(%rbp),%esi
movzbl -0x1a(%rbp),%edx
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112f <print_packet+0x1f>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_packet>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     1160 <print_packet+0x40>
mov    %rsi,%r12
mov    %rdi,%r14
lea    0xec6(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
movzbl (%r14,%rbx,1),%edx
mov    %edx,%esi
shr    $0x4,%esi
and    $0xf,%edx
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <print_packet+0x20>
lea    0xe9f(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <puts@plt>

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

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