#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 */
scalar_t__ sprintf(char *, char *, unsigned char);
char *print_pkt(char *p, int len) {
  static char buf[3000];
  int i, l = 0;
  for (i = 0; i < len; i++)
    l += sprintf(buf + l, "%02X", (unsigned char)p[i]);
  return buf;
}


x86 assembly (clang, -O0):
<print_pkt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117a <print_pkt+0x6a>
movslq -0x14(%rbp),%rax
lea    0x2efc(%rip),%rdi
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xeaa(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1030 <sprintf@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112d <print_pkt+0x1d>
lea    0x2ebf(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_pkt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1162 <print_pkt+0x52>
mov    %rdi,%r15
mov    %esi,%r12d
xor    %ebx,%ebx
lea    0x2f12(%rip),%r13
lea    0xecb(%rip),%r14
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
movslq %eax,%rbp
mov    %r13,%rdi
add    %rbp,%rdi
movzbl (%r15,%rbx,1),%edx
mov    %r14,%rsi
call   1030 <sprintf@plt>
add    %rbp,%rax
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <print_pkt+0x30>
lea    0x2ed7(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@print_pkt.buf = internal global [3000 x i8] zeroinitializer
@.str = [5 x i8] c"%02X\00"
define i8* @print_pkt(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %6
store i32 0, i32* %5
br label %7
7: ; preds = %25, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %28
11: ; preds = %7
%12 = load i32, i32* %6
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* getelementptr inbounds ([3000 x i8], [3000 x i8]* @print_pkt.buf, i64 0, i64 0), i64 %13
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = call i64 @sprintf(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %19)
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = add nsw i64 %22, %20
%24 = trunc i64 %23 to i32
store i32 %24, i32* %6
br label %25
25: ; preds = %11
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %7
28: ; preds = %7
ret i8* getelementptr inbounds ([3000 x i8], [3000 x i8]* @print_pkt.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@print_pkt.buf = internal global [3000 x i8] zeroinitializer
@.str = [5 x i8] c"%02X\00"
define i8* @print_pkt(i8* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %18
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %16, %6 ]
%8 = phi i64 [ 0, %4 ], [ %15, %6 ]
%9 = shl i64 %8, 32
%10 = ashr exact i64 %9, 32
%11 = getelementptr inbounds [3000 x i8], [3000 x i8]* @print_pkt.buf, i64 0, i64 %10
%12 = getelementptr inbounds i8, i8* %0, i64 %7
%13 = load i8, i8* %12
%14 = tail call i64 @sprintf(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %13)
%15 = add nsw i64 %14, %10
%16 = add nuw nsw i64 %7, 1
%17 = icmp eq i64 %16, %5
br i1 %17, label %18, label %6
18: ; preds = %6, %2
ret i8* getelementptr inbounds ([3000 x i8], [3000 x i8]* @print_pkt.buf, i64 0, i64 0)
}