void asn1StoreLength(unsigned char **Ref, int Length) {
  if (Length >= 256) {
    *(*Ref)++ = 0x82;
    *(*Ref)++ = (unsigned char)(Length >> 8);
    *(*Ref)++ = (unsigned char)(Length & 0xFF);
  } else if (Length >= 128) {
    *(*Ref)++ = 0x81;
    *(*Ref)++ = (unsigned char)Length;
  } else
    *(*Ref)++ = (unsigned char)Length;
}


x86 assembly (clang, -O0):
<asn1StoreLength>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x100,-0xc(%rbp)
jl     1169 <asn1StoreLength+0x69>
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,(%rcx)
movb   $0x82,(%rax)
mov    -0xc(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
jmp    11c4 <asn1StoreLength+0xc4>
cmpl   $0x80,-0xc(%rbp)
jl     11a7 <asn1StoreLength+0xa7>
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,(%rcx)
movb   $0x81,(%rax)
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
jmp    11bf <asn1StoreLength+0xbf>
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
jmp    11c4 <asn1StoreLength+0xc4>
pop    %rbp
ret

x86 assembly (clang, -O2):
<asn1StoreLength>:
mov    %esi,%eax
cmp    $0x100,%esi
jl     1125 <asn1StoreLength+0x25>
mov    (%rdi),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rdi)
movb   $0x82,(%rcx)
mov    (%rdi),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rdi)
mov    %ah,(%rcx)
jmp    1139 <asn1StoreLength+0x39>
cmp    $0x80,%eax
jl     1139 <asn1StoreLength+0x39>
mov    (%rdi),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rdi)
movb   $0x81,(%rcx)
mov    (%rdi),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rdi)
mov    %al,(%rcx)
ret

LLVM IR (-O0):
define void @asn1StoreLength(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
store i8** %0, i8*** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = icmp sge i32 %5, 256
br i1 %6, label %7, label %23
7: ; preds = %2
%8 = load i8**, i8*** %3
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %8
store i8 -126, i8* %9
%11 = load i32, i32* %4
%12 = ashr i32 %11, 8
%13 = trunc i32 %12 to i8
%14 = load i8**, i8*** %3
%15 = load i8*, i8** %14
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %14
store i8 %13, i8* %15
%17 = load i32, i32* %4
%18 = and i32 %17, 255
%19 = trunc i32 %18 to i8
%20 = load i8**, i8*** %3
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %20
store i8 %19, i8* %21
br label %42
23: ; preds = %2
%24 = load i32, i32* %4
%25 = icmp sge i32 %24, 128
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i8**, i8*** %3
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %27
store i8 -127, i8* %28
%30 = load i32, i32* %4
%31 = trunc i32 %30 to i8
%32 = load i8**, i8*** %3
%33 = load i8*, i8** %32
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %32
store i8 %31, i8* %33
br label %41
35: ; preds = %23
%36 = load i32, i32* %4
%37 = trunc i32 %36 to i8
%38 = load i8**, i8*** %3
%39 = load i8*, i8** %38
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %38
store i8 %37, i8* %39
br label %41
41: ; preds = %35, %26
br label %42
42: ; preds = %41, %7
ret void
}

LLVM IR (-O2):
define void @asn1StoreLength(i8** nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 255
br i1 %3, label %4, label %14
4: ; preds = %2
%5 = load i8*, i8** %0
%6 = getelementptr inbounds i8, i8* %5, i64 1
store i8* %6, i8** %0
store i8 -126, i8* %5
%7 = lshr i32 %1, 8
%8 = trunc i32 %7 to i8
%9 = load i8*, i8** %0
%10 = getelementptr inbounds i8, i8* %9, i64 1
store i8* %10, i8** %0
store i8 %8, i8* %9
%11 = trunc i32 %1 to i8
%12 = load i8*, i8** %0
%13 = getelementptr inbounds i8, i8* %12, i64 1
store i8* %13, i8** %0
store i8 %11, i8* %12
br label %26
14: ; preds = %2
%15 = icmp sgt i32 %1, 127
br i1 %15, label %16, label %22
16: ; preds = %14
%17 = load i8*, i8** %0
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8* %18, i8** %0
store i8 -127, i8* %17
%19 = trunc i32 %1 to i8
%20 = load i8*, i8** %0
%21 = getelementptr inbounds i8, i8* %20, i64 1
store i8* %21, i8** %0
store i8 %19, i8* %20
br label %26
22: ; preds = %14
%23 = trunc i32 %1 to i8
%24 = load i8*, i8** %0
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8* %25, i8** %0
store i8 %23, i8* %24
br label %26
26: ; preds = %16, %22, %4
ret void
}