int PadingBuffer(char *pOutBuf, int nLen) {
  int len = nLen;
  if (len < 6) {
    *pOutBuf++ = 0xff;
    *pOutBuf++ = 0xff;
    *pOutBuf++ = 0xff;
    *pOutBuf++ = 0xff;
    *pOutBuf++ = 0xff;
    *pOutBuf++ = 0xff;
    return 0;
  }
  len -= 6;
  *pOutBuf++ = 0x00;
  *pOutBuf++ = 0x00;
  *pOutBuf++ = 0x01;
  *pOutBuf++ = 0xBE;
  *pOutBuf++ = len >> 8;
  *pOutBuf++ = len & 0xff;
  for (; len > 0; len--)
    *pOutBuf++ = 0xff;
  return nLen + 6;
}


x86 assembly (clang, -O0):
<PadingBuffer>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x6,-0x18(%rbp)
jge    1193 <PadingBuffer+0x93>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0xff,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0xff,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0xff,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0xff,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0xff,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0xff,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    124b <PadingBuffer+0x14b>
mov    -0x18(%rbp),%eax
sub    $0x6,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x1,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0xbe,(%rax)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
cmpl   $0x0,-0x18(%rbp)
jle    1242 <PadingBuffer+0x142>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0xff,(%rax)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1218 <PadingBuffer+0x118>
mov    -0x14(%rbp),%eax
add    $0x6,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<PadingBuffer>:
push   %rbx
cmp    $0x5,%esi
jg     1126 <PadingBuffer+0x16>
movw   $0xffff,0x4(%rdi)
movl   $0xffffffff,(%rdi)
xor    %ebx,%ebx
jmp    114f <PadingBuffer+0x3f>
mov    %esi,%ebx
lea    -0x6(%rbx),%eax
movl   $0xbe010000,(%rdi)
mov    %ah,0x4(%rdi)
mov    %al,0x5(%rdi)
cmp    $0x6,%esi
je     114c <PadingBuffer+0x3c>
add    $0x6,%rdi
mov    %eax,%edx
mov    $0xff,%esi
call   1030 <memset@plt>
add    $0x6,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @PadingBuffer(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 6
br i1 %9, label %10, label %23
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %4
store i8 -1, i8* %11
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %4
store i8 -1, i8* %13
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %4
store i8 -1, i8* %15
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %4
store i8 -1, i8* %17
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %4
store i8 -1, i8* %19
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %4
store i8 -1, i8* %21
store i32 0, i32* %3
br label %56
23: ; preds = %2
%24 = load i32, i32* %6
%25 = sub nsw i32 %24, 6
store i32 %25, i32* %6
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
store i8 0, i8* %26
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
store i8 0, i8* %28
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %4
store i8 1, i8* %30
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %4
store i8 -66, i8* %32
%34 = load i32, i32* %6
%35 = ashr i32 %34, 8
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %4
store i8 %36, i8* %37
%39 = load i32, i32* %6
%40 = and i32 %39, 255
%41 = trunc i32 %40 to i8
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %4
store i8 %41, i8* %42
br label %44
44: ; preds = %50, %23
%45 = load i32, i32* %6
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %53
47: ; preds = %44
%48 = load i8*, i8** %4
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %4
store i8 -1, i8* %48
br label %50
50: ; preds = %47
%51 = load i32, i32* %6
%52 = add nsw i32 %51, -1
store i32 %52, i32* %6
br label %44
53: ; preds = %44
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 6
store i32 %55, i32* %3
br label %56
56: ; preds = %53, %10
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
define i32 @PadingBuffer(i8* nocapture writeonly %0, i32 %1) {
%3 = icmp slt i32 %1, 6
br i1 %3, label %4, label %5
4: ; preds = %2
br label %21
5: ; preds = %2
%6 = add nsw i32 %1, -6
%7 = getelementptr inbounds i8, i8* %0, i64 1
store i8 0, i8* %0
%8 = getelementptr inbounds i8, i8* %0, i64 2
store i8 0, i8* %7
%9 = getelementptr inbounds i8, i8* %0, i64 3
store i8 1, i8* %8
%10 = getelementptr inbounds i8, i8* %0, i64 4
store i8 -66, i8* %9
%11 = lshr i32 %6, 8
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds i8, i8* %0, i64 5
store i8 %12, i8* %10
%14 = trunc i32 %6 to i8
store i8 %14, i8* %13
%15 = icmp eq i32 %1, 6
br i1 %15, label %19, label %16
16: ; preds = %5
%17 = getelementptr i8, i8* %0, i64 6
%18 = zext i32 %6 to i64
br label %19
19: ; preds = %16, %5
%20 = add nuw nsw i32 %1, 6
br label %21
21: ; preds = %19, %4
%22 = phi i32 [ 0, %4 ], [ %20, %19 ]
ret i32 %22
}