void add_tail(unsigned char target[], int tp, const int tail_length) {
  int i, prn, temp;
  for (i = tail_length; i > 0; i--) {
    if (i == tail_length) {
      target[tp] = 129;
      tp++;
    } else {
      prn = ((149 * (tp + 1)) % 253) + 1;
      temp = 129 + prn;
      if (temp <= 254) {
        target[tp] = (unsigned char)(temp);
        tp++;
      } else {
        target[tp] = (unsigned char)(temp - 254);
        tp++;
      }
    }
  }
}


x86 assembly (clang, -O0):
<add_tail>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11ca <add_tail+0xca>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    1144 <add_tail+0x44>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x81,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b7 <add_tail+0xb7>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
imul   $0x95,%eax,%eax
mov    $0xfd,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x81,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0xfe,-0x1c(%rbp)
jg     1194 <add_tail+0x94>
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b2 <add_tail+0xb2>
mov    -0x1c(%rbp),%eax
sub    $0xfe,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b7 <add_tail+0xb7>
jmp    11bc <add_tail+0xbc>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1114 <add_tail+0x14>
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_tail>:
test   %edx,%edx
jle    1514 <add_tail+0x414>
movslq %esi,%rax
movb   $0x81,(%rdi,%rax,1)
cmp    $0x1,%edx
je     1514 <add_tail+0x414>
add    $0x1,%esi
xor    %ecx,%ecx
mov    %edx,%eax
sub    $0x2,%eax
cmovb  %ecx,%eax
add    $0x1,%eax
cmp    $0x10,%eax
jae    1135 <add_tail+0x35>
mov    %esi,%r8d
jmp    14b1 <add_tail+0x3b1>
mov    %eax,%r9d
and    $0xfffffff0,%r9d
lea    (%rsi,%r9,1),%r8d
sub    %r9d,%edx
movd   %esi,%xmm0
pshufd $0x0,%xmm0,%xmm9
movdqa 0xeaa(%rip),%xmm10
paddd  %xmm9,%xmm10
movdqa 0xead(%rip),%xmm2
paddd  %xmm9,%xmm2
movdqa 0xeb0(%rip),%xmm3
paddd  %xmm9,%xmm3
paddd  0xeb2(%rip),%xmm9
movdqa 0xeb9(%rip),%xmm14
movdqa 0xec0(%rip),%xmm15
movdqa 0xec7(%rip),%xmm13
movdqa 0xf0e(%rip),%xmm12
mov    %r9d,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
movdqa %xmm10,%xmm4
pmuludq %xmm14,%xmm4
pshufd $0xe8,%xmm4,%xmm8
pshufd $0xf5,%xmm10,%xmm4
pmuludq %xmm14,%xmm4
pshufd $0xe8,%xmm4,%xmm4
punpckldq %xmm4,%xmm8
movdqa %xmm2,%xmm4
pmuludq %xmm14,%xmm4
pshufd $0xe8,%xmm4,%xmm6
pshufd $0xf5,%xmm2,%xmm4
pmuludq %xmm14,%xmm4
pshufd $0xe8,%xmm4,%xmm4
punpckldq %xmm4,%xmm6
movdqa %xmm3,%xmm4
pmuludq %xmm14,%xmm4
pshufd $0xe8,%xmm4,%xmm5
pshufd $0xf5,%xmm3,%xmm4
pmuludq %xmm14,%xmm4
pshufd $0xe8,%xmm4,%xmm4
punpckldq %xmm4,%xmm5
movdqa %xmm9,%xmm4
pmuludq %xmm14,%xmm4
pshufd $0xe8,%xmm4,%xmm4
pshufd $0xf5,%xmm9,%xmm1
pmuludq %xmm14,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm4
paddd  %xmm14,%xmm4
paddd  %xmm14,%xmm5
paddd  %xmm14,%xmm6
paddd  %xmm14,%xmm8
pxor   %xmm1,%xmm1
pcmpgtd %xmm8,%xmm1
pand   %xmm15,%xmm1
paddd  %xmm8,%xmm1
movdqa %xmm8,%xmm7
pmuludq %xmm15,%xmm7
pshufd $0xed,%xmm7,%xmm7
pshufd $0xf5,%xmm8,%xmm0
pmuludq %xmm15,%xmm0
pshufd $0xed,%xmm0,%xmm0
punpckldq %xmm0,%xmm7
psubd  %xmm1,%xmm7
paddd  %xmm8,%xmm7
movdqa %xmm7,%xmm0
psrld  $0x1f,%xmm0
psrad  $0x7,%xmm7
paddd  %xmm0,%xmm7
pshufd $0xf5,%xmm7,%xmm0
pmuludq %xmm13,%xmm7
pshufd $0xe8,%xmm7,%xmm1
pmuludq %xmm13,%xmm0
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm0,%xmm1
psubd  %xmm1,%xmm8
pxor   %xmm0,%xmm0
pcmpgtd %xmm6,%xmm0
pand   %xmm15,%xmm0
paddd  %xmm6,%xmm0
movdqa %xmm6,%xmm1
pmuludq %xmm15,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm6,%xmm7
pmuludq %xmm15,%xmm7
pshufd $0xed,%xmm7,%xmm7
punpckldq %xmm7,%xmm1
psubd  %xmm0,%xmm1
paddd  %xmm6,%xmm1
movdqa %xmm1,%xmm0
psrld  $0x1f,%xmm0
psrad  $0x7,%xmm1
paddd  %xmm0,%xmm1
pshufd $0xf5,%xmm1,%xmm0
pmuludq %xmm13,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm13,%xmm0
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm0,%xmm1
psubd  %xmm1,%xmm6
pxor   %xmm0,%xmm0
pcmpgtd %xmm5,%xmm0
pand   %xmm15,%xmm0
paddd  %xmm5,%xmm0
movdqa %xmm5,%xmm1
pmuludq %xmm15,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm5,%xmm7
pmuludq %xmm15,%xmm7
pshufd $0xed,%xmm7,%xmm7
punpckldq %xmm7,%xmm1
psubd  %xmm0,%xmm1
paddd  %xmm5,%xmm1
movdqa %xmm1,%xmm0
psrld  $0x1f,%xmm0
psrad  $0x7,%xmm1
paddd  %xmm0,%xmm1
pshufd $0xf5,%xmm1,%xmm0
pmuludq %xmm13,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm13,%xmm0
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm0,%xmm1
psubd  %xmm1,%xmm5
pxor   %xmm0,%xmm0
pcmpgtd %xmm4,%xmm0
pand   %xmm15,%xmm0
paddd  %xmm4,%xmm0
movdqa %xmm4,%xmm1
pmuludq %xmm15,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm4,%xmm7
pmuludq %xmm15,%xmm7
pshufd $0xed,%xmm7,%xmm7
punpckldq %xmm7,%xmm1
psubd  %xmm0,%xmm1
paddd  %xmm4,%xmm1
movdqa %xmm1,%xmm0
psrld  $0x1f,%xmm0
psrad  $0x7,%xmm1
paddd  %xmm0,%xmm1
pshufd $0xf5,%xmm1,%xmm0
pmuludq %xmm13,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm13,%xmm0
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm0,%xmm1
psubd  %xmm1,%xmm4
movdqa 0xc60(%rip),%xmm1
movdqa %xmm1,%xmm11
pcmpgtd %xmm4,%xmm11
movdqa %xmm1,%xmm0
pcmpgtd %xmm5,%xmm0
packssdw %xmm0,%xmm11
movdqa %xmm1,%xmm0
pcmpgtd %xmm6,%xmm0
pcmpgtd %xmm8,%xmm1
packssdw %xmm1,%xmm0
packsswb %xmm0,%xmm11
movdqa 0xc3b(%rip),%xmm0
pand   %xmm0,%xmm4
pand   %xmm0,%xmm5
packuswb %xmm5,%xmm4
pand   %xmm0,%xmm6
pand   %xmm0,%xmm8
packuswb %xmm8,%xmm6
packuswb %xmm6,%xmm4
movdqa %xmm11,%xmm0
pandn  0xc20(%rip),%xmm0
pand   0xc27(%rip),%xmm11
por    %xmm0,%xmm11
paddb  %xmm4,%xmm11
movslq %esi,%rsi
movdqu %xmm11,(%rdi,%rsi,1)
paddd  %xmm12,%xmm9
paddd  %xmm12,%xmm3
paddd  %xmm12,%xmm2
paddd  %xmm12,%xmm10
add    $0x10,%esi
add    $0xfffffff0,%ecx
jne    11b0 <add_tail+0xb0>
cmp    %r9d,%eax
je     1514 <add_tail+0x414>
movslq %r8d,%rax
add    %rax,%rdi
imul   $0x95,%eax,%eax
add    $0x95,%eax
add    $0x1,%edx
cs nopw 0x0(%rax,%rax,1)
nop
cltq
imul   $0xffffffff81848da9,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%esi
shr    $0x1f,%esi
sar    $0x7,%ecx
add    %esi,%ecx
imul   $0xfd,%ecx,%ecx
mov    %eax,%esi
sub    %ecx,%esi
cmp    $0x7d,%esi
setge  %cl
add    %cl,%cl
add    %sil,%cl
add    $0x82,%cl
mov    %cl,(%rdi)
add    $0x1,%rdi
add    $0x95,%eax
add    $0xffffffff,%edx
cmp    $0x2,%edx
ja     14d0 <add_tail+0x3d0>
ret

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

LLVM IR (-O2):
define void @add_tail(i8* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %58
5: ; preds = %3
%6 = sext i32 %1 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
store i8 -127, i8* %7
%8 = add nsw i32 %1, 1
%9 = icmp eq i32 %2, 1
br i1 %9, label %58, label %10
10: ; preds = %5
%11 = add i32 %2, 1
%12 = call i32 @llvm.umin.i32(i32 %2, i32 2)
%13 = sub i32 %11, %12
%14 = icmp ult i32 %13, 16
br i1 %14, label %41, label %15
15: ; preds = %10
%16 = and i32 %13, -16
%17 = add i32 %8, %16
%18 = sub i32 %2, %16
%19 = insertelement <16 x i32> poison, i32 %8, i64 0
%20 = shufflevector <16 x i32> %19, <16 x i32> poison, <16 x i32> zeroinitializer
%21 = add <16 x i32> %20, <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
br label %22
22: ; preds = %22, %15
%23 = phi i32 [ 0, %15 ], [ %36, %22 ]
%24 = phi <16 x i32> [ %21, %15 ], [ %37, %22 ]
%25 = add i32 %8, %23
%26 = mul <16 x i32> %24, <i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149>
%27 = add <16 x i32> %26, <i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149, i32 149>
%28 = srem <16 x i32> %27, <i32 253, i32 253, i32 253, i32 253, i32 253, i32 253, i32 253, i32 253, i32 253, i32 253, i32 253, i32 253, i32 253, i32 253, i32 253, i32 253>
%29 = icmp slt <16 x i32> %28, <i32 125, i32 125, i32 125, i32 125, i32 125, i32 125, i32 125, i32 125, i32 125, i32 125, i32 125, i32 125, i32 125, i32 125, i32 125, i32 125>
%30 = trunc <16 x i32> %28 to <16 x i8>
%31 = select <16 x i1> %29, <16 x i8> <i8 -126, i8 -126, i8 -126, i8 -126, i8 -126, i8 -126, i8 -126, i8 -126, i8 -126, i8 -126, i8 -126, i8 -126, i8 -126, i8 -126, i8 -126, i8 -126>, <16 x i8> <i8 -124, i8 -124, i8 -124, i8 -124, i8 -124, i8 -124, i8 -124, i8 -124, i8 -124, i8 -124, i8 -124, i8 -124, i8 -124, i8 -124, i8 -124, i8 -124>
%32 = add <16 x i8> %31, %30
%33 = sext i32 %25 to i64
%34 = getelementptr inbounds i8, i8* %0, i64 %33
%35 = bitcast i8* %34 to <16 x i8>*
store <16 x i8> %32, <16 x i8>* %35
%36 = add nuw i32 %23, 16
%37 = add <16 x i32> %24, <i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16>
%38 = icmp eq i32 %36, %16
br i1 %38, label %39, label %22
39: ; preds = %22
%40 = icmp eq i32 %13, %16
br i1 %40, label %58, label %41
41: ; preds = %10, %39
%42 = phi i32 [ %8, %10 ], [ %17, %39 ]
%43 = phi i32 [ %2, %10 ], [ %18, %39 ]
br label %44
44: ; preds = %41, %44
%45 = phi i32 [ %48, %44 ], [ %42, %41 ]
%46 = phi i32 [ %47, %44 ], [ %43, %41 ]
%47 = add nsw i32 %46, -1
%48 = add nsw i32 %45, 1
%49 = mul nsw i32 %48, 149
%50 = srem i32 %49, 253
%51 = icmp slt i32 %50, 125
%52 = trunc i32 %50 to i8
%53 = select i1 %51, i8 -126, i8 -124
%54 = add i8 %53, %52
%55 = sext i32 %45 to i64
%56 = getelementptr inbounds i8, i8* %0, i64 %55
store i8 %54, i8* %56
%57 = icmp ugt i32 %46, 2
br i1 %57, label %44, label %58
58: ; preds = %44, %39, %5, %3
ret void
}