int _fillbyte(int byte, unsigned char *bufferp, int blen) {
  if (byte == 0xce || byte == 0xcc) {
    if (blen >= 2) {
      *bufferp++ = 0xcc;
      *bufferp++ = byte & 0x7f;
      return (2);
    }
  } else if (blen > 0) {
    *bufferp++ = byte;
    return (1);
  }
  return (-1);
}


x86 assembly (clang, -O0):
<_fillbyte>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0xce,-0x8(%rbp)
je     1128 <_fillbyte+0x28>
cmpl   $0xcc,-0x8(%rbp)
jne    116e <_fillbyte+0x6e>
cmpl   $0x2,-0x14(%rbp)
jl     1169 <_fillbyte+0x69>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0xcc,(%rax)
mov    -0x8(%rbp),%eax
and    $0x7f,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
movl   $0x2,-0x4(%rbp)
jmp    11a6 <_fillbyte+0xa6>
jmp    119f <_fillbyte+0x9f>
cmpl   $0x0,-0x14(%rbp)
jle    119a <_fillbyte+0x9a>
mov    -0x8(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11a6 <_fillbyte+0xa6>
jmp    119f <_fillbyte+0x9f>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<_fillbyte>:
mov    %edi,%eax
and    $0xfffffffd,%eax
cmp    $0xcc,%eax
jne    1127 <_fillbyte+0x27>
mov    $0xffffffff,%eax
cmp    $0x2,%edx
jl     1133 <_fillbyte+0x33>
movb   $0xcc,(%rsi)
and    $0x7f,%dil
mov    %dil,0x1(%rsi)
mov    $0x2,%eax
ret
test   %edx,%edx
jle    1134 <_fillbyte+0x34>
mov    %dil,(%rsi)
mov    $0x1,%eax
ret
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
define i32 @_fillbyte(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 206
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 204
br i1 %12, label %13, label %25
13: ; preds = %10, %3
%14 = load i32, i32* %7
%15 = icmp sge i32 %14, 2
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %6
store i8 -52, i8* %17
%19 = load i32, i32* %5
%20 = and i32 %19, 127
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %6
store i8 %21, i8* %22
store i32 2, i32* %4
br label %35
24: ; preds = %13
br label %34
25: ; preds = %10
%26 = load i32, i32* %7
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i32, i32* %5
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %6
store i8 %30, i8* %31
store i32 1, i32* %4
br label %35
33: ; preds = %25
br label %34
34: ; preds = %33, %24
store i32 -1, i32* %4
br label %35
35: ; preds = %34, %28, %16
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
define i32 @_fillbyte(i32 %0, i8* nocapture writeonly %1, i32 %2) {
%4 = and i32 %0, -3
%5 = icmp eq i32 %4, 204
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = icmp sgt i32 %2, 1
br i1 %7, label %8, label %16
8: ; preds = %6
%9 = getelementptr inbounds i8, i8* %1, i64 1
store i8 -52, i8* %1
%10 = trunc i32 %0 to i8
%11 = and i8 %10, 127
store i8 %11, i8* %9
br label %16
12: ; preds = %3
%13 = icmp sgt i32 %2, 0
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = trunc i32 %0 to i8
store i8 %15, i8* %1
br label %16
16: ; preds = %6, %12, %14, %8
%17 = phi i32 [ 2, %8 ], [ 1, %14 ], [ -1, %12 ], [ -1, %6 ]
ret i32 %17
}