#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 size_t sz;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
unsigned char *packet_header(size_t sz, unsigned char *ptr) {
  static const char hex[] = "0123456789abcdef";
  assert(sz < 65536);
  ptr[0] = hex[(sz >> 12) & 15];
  ptr[1] = hex[(sz >> 8) & 15];
  ptr[2] = hex[(sz >> 4) & 15];
  ptr[3] = hex[(sz)&15];
  assert(4 == 4);
  return ptr + 4;
}


x86 assembly (clang, -O0):
<packet_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x10000,-0x8(%rbp)
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rcx
shr    $0xc,%rcx
and    $0xf,%rcx
lea    0xeb8(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rcx
shr    $0x8,%rcx
and    $0xf,%rcx
lea    0xe9c(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x8(%rbp),%rcx
shr    $0x4,%rcx
and    $0xf,%rcx
lea    0xe7f(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x8(%rbp),%rcx
and    $0xf,%rcx
lea    0xe66(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
mov    $0x1,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<packet_header>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edi,%edi
cmp    $0x10000,%rbx
setb   %dil
call   1030 <assert@plt>
mov    %ebx,%eax
shr    $0xc,%eax
and    $0xf,%eax
lea    0xec5(%rip),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,(%r14)
mov    %ebx,%eax
shr    $0x8,%eax
and    $0xf,%eax
mov    (%rax,%rcx,1),%al
mov    %al,0x1(%r14)
mov    %ebx,%eax
shr    $0x4,%eax
and    $0xf,%eax
mov    (%rax,%rcx,1),%al
mov    %al,0x2(%r14)
and    $0xf,%ebx
mov    (%rbx,%rcx,1),%al
mov    %al,0x3(%r14)
mov    $0x1,%edi
call   1030 <assert@plt>
add    $0x4,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@packet_header.hex = internal constant [17 x i8] c"0123456789abcdef\00"
define i8* @packet_header(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
store i64 %0, i64* %3
store i8* %1, i8** %4
%5 = load i64, i64* %3
%6 = icmp ult i64 %5, 65536
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i64, i64* %3
%10 = lshr i64 %9, 12
%11 = and i64 %10, 15
%12 = getelementptr inbounds [17 x i8], [17 x i8]* @packet_header.hex, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 0
store i8 %13, i8* %15
%16 = load i64, i64* %3
%17 = lshr i64 %16, 8
%18 = and i64 %17, 15
%19 = getelementptr inbounds [17 x i8], [17 x i8]* @packet_header.hex, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8 %20, i8* %22
%23 = load i64, i64* %3
%24 = lshr i64 %23, 4
%25 = and i64 %24, 15
%26 = getelementptr inbounds [17 x i8], [17 x i8]* @packet_header.hex, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 2
store i8 %27, i8* %29
%30 = load i64, i64* %3
%31 = and i64 %30, 15
%32 = getelementptr inbounds [17 x i8], [17 x i8]* @packet_header.hex, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i64 3
store i8 %33, i8* %35
%36 = call i32 @assert(i32 1)
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i64 4
ret i8* %38
}

LLVM IR (-O2):
@packet_header.hex = internal unnamed_addr constant [17 x i8] c"0123456789abcdef\00"
define i8* @packet_header(i64 %0, i8* writeonly %1) {
%3 = icmp ult i64 %0, 65536
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = lshr i64 %0, 12
%7 = and i64 %6, 15
%8 = getelementptr inbounds [17 x i8], [17 x i8]* @packet_header.hex, i64 0, i64 %7
%9 = load i8, i8* %8
store i8 %9, i8* %1
%10 = lshr i64 %0, 8
%11 = and i64 %10, 15
%12 = getelementptr inbounds [17 x i8], [17 x i8]* @packet_header.hex, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %13, i8* %14
%15 = lshr i64 %0, 4
%16 = and i64 %15, 15
%17 = getelementptr inbounds [17 x i8], [17 x i8]* @packet_header.hex, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %18, i8* %19
%20 = and i64 %0, 15
%21 = getelementptr inbounds [17 x i8], [17 x i8]* @packet_header.hex, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %22, i8* %23
%24 = tail call i32 @assert(i32 1)
%25 = getelementptr inbounds i8, i8* %1, i64 4
ret i8* %25
}