#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 */

/* Variables and functions */
int /*<<< orphan*/ asn1StoreLength(unsigned char **, int);
int /*<<< orphan*/ asn1StoreTag(unsigned char **, unsigned short);
int /*<<< orphan*/ memmove(unsigned char *, unsigned char *, int);
int asn1Encap(unsigned short Tag, unsigned char *Msg, int MsgLen) {
  unsigned char tmpbuf[6], *po;
  int len;
  po = tmpbuf;
  asn1StoreTag(&po, Tag);
  asn1StoreLength(&po, MsgLen);
  len = (int)(po - tmpbuf);
  memmove(Msg + len, Msg, MsgLen);
  memmove(Msg, tmpbuf, len);
  return MsgLen + len;
}


x86 assembly (clang, -O0):
<asn1Encap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x1a(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
movzwl -0x2(%rbp),%esi
call   1050 <asn1StoreTag@plt>
mov    -0x14(%rbp),%esi
lea    -0x28(%rbp),%rdi
call   1040 <asn1StoreLength@plt>
mov    -0x28(%rbp),%rax
lea    -0x1a(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <memmove@plt>
mov    -0x10(%rbp),%rdi
lea    -0x1a(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <memmove@plt>
mov    -0x14(%rbp),%eax
add    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asn1Encap>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %edi,%esi
lea    0xa(%rsp),%r14
mov    %r14,(%rsp)
mov    %rsp,%r15
mov    %r15,%rdi
call   1050 <asn1StoreTag@plt>
mov    %r15,%rdi
mov    %r12d,%esi
call   1040 <asn1StoreLength@plt>
mov    (%rsp),%rax
sub    %r14,%rax
movslq %eax,%rbp
lea    (%rbx,%rbp,1),%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <memmove@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <memmove@plt>
add    %r12d,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @asn1Encap(i16 zeroext %0, i8* %1, i32 %2) {
%4 = alloca i16
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [6 x i8]
%8 = alloca i8*
%9 = alloca i32
store i16 %0, i16* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
store i8* %10, i8** %8
%11 = load i16, i16* %4
%12 = call i32 @asn1StoreTag(i8** %8, i16 zeroext %11)
%13 = load i32, i32* %6
%14 = call i32 @asn1StoreLength(i8** %8, i32 %13)
%15 = load i8*, i8** %8
%16 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%17 = ptrtoint i8* %15 to i64
%18 = ptrtoint i8* %16 to i64
%19 = sub i64 %17, %18
%20 = trunc i64 %19 to i32
store i32 %20, i32* %9
%21 = load i8*, i8** %5
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8*, i8** %5
%26 = load i32, i32* %6
%27 = call i32 @memmove(i8* %24, i8* %25, i32 %26)
%28 = load i8*, i8** %5
%29 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%30 = load i32, i32* %9
%31 = call i32 @memmove(i8* %28, i8* %29, i32 %30)
%32 = load i32, i32* %6
%33 = load i32, i32* %9
%34 = add nsw i32 %32, %33
ret i32 %34
}

LLVM IR (-O2):
define i32 @asn1Encap(i16 zeroext %0, i8* %1, i32 %2) {
%4 = alloca [6 x i8]
%5 = alloca i8*
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%7 = bitcast i8** %5 to i8*
store i8* %6, i8** %5
%8 = call i32 @asn1StoreTag(i8** %5, i16 zeroext %0)
%9 = call i32 @asn1StoreLength(i8** %5, i32 %2)
%10 = load i8*, i8** %5
%11 = ptrtoint i8* %10 to i64
%12 = ptrtoint [6 x i8]* %4 to i64
%13 = sub i64 %11, %12
%14 = trunc i64 %13 to i32
%15 = shl i64 %13, 32
%16 = ashr exact i64 %15, 32
%17 = getelementptr inbounds i8, i8* %1, i64 %16
%18 = call i32 @memmove(i8* %17, i8* %1, i32 %2)
%19 = call i32 @memmove(i8* %1, i8* %6, i32 %14)
%20 = add nsw i32 %14, %2
ret i32 %20
}