// File: /workspace/github_cpp_makefile_star2_O3/tap3edit[P]tap3xml/AsnItem.cpp
// Function: AsnItem::encode[abi:cxx11](int)
string AsnItem::encode(int depth)
{

    long                            tmp_int;
    int                             i=1, j;
    ostringstream                   enc_str;
    string                          str, enc;
    extern map<int, enc_dec_funcs>  simpletypes;

    (void) depth; // not used

    if (!_tree)
    {
        cerr << "treenode structure was not set with tree() method";
        err_trace(__FILE__, __LINE__);
    }

    if (!_tree->tag_d)
        return "";

    _tree->tag_l=0;
    memset(_tree->tag_x,  '\0', 4);

    _tree->size_l=0;
    memset(_tree->size_x, '\0', 5);


    /* 1. Build Tag since _tree->tag_x is not mandatory */

    _tree->cl=1;
    _tree->tag_x[0]=(_tree->cl<<6)+(_tree->pc<<5)+(_tree->tag_d&0x1F);
    _tree->tag_l=1;

    if ( _tree->tag_d >> 5 || _tree->tag_d == 0x1F)
    {
        /* 1.1 Tag should have more than one octet */

        if ( _tree->tag_d >> 26 )
        {
            /* Note: we need to count just the bits used by the tag  */
            /*       without clase, primitive/contructed and so on.  */
            /*       That is why we take 26 and not 32.              */

            cerr << "Found tag bigger than 4 bytes. Tag:" << _tree->tag_d;
            err_trace(__FILE__, __LINE__);
        }

        _tree->tag_x[0]=(_tree->cl<<6)+(_tree->pc<<5)+(0x1F);

        tmp_int=_tree->tag_d;

        while (tmp_int)
        {
            for(j=i++;j>0;j--)
                _tree->tag_x[j]=_tree->tag_x[j-1];
                
            _tree->tag_x[1]=(uchar)((1<<7)+(tmp_int&0x7F));
            tmp_int>>=7;
        }

        _tree->tag_x[i-1]&=0x7F;
        _tree->tag_l=i;

    }


    /* 2. Build Size */

    if ( _tree->size_d >> 7 )
    {
        /* Then size should have more than one octet */


        tmp_int=_tree->size_d;
        i=1;

        while (tmp_int)
        {
            for(j=i++;j>0;j--)
                _tree->size_x[j]=_tree->size_x[j-1];
                
            _tree->size_x[1]=(uchar)tmp_int&0xFF;
            tmp_int>>=8;
        }

        _tree->size_x[0]=(uchar)((1<<7)+(i-1));
        _tree->size_l=i;
        
    }
    else
    {
        /* Size should have just one octet */

        _tree->size_x[0]=(uchar)_tree->size_d;
        _tree->size_l=1;

    }


    /* 3. Prepare encoded String */

    if (!_tree->pc )
    {
        str.assign((char *)_tree->tag_x,_tree->tag_l);
        enc+=str;
        str.assign((char *)_tree->size_x,_tree->size_l);
        enc+=str;
        enc+=(*simpletypes[_tree->type].encode)(*_tree->value);
    }
    else
    {
        str.assign((char *)_tree->tag_x,_tree->tag_l);
        enc+=str;
        str.assign((char *)_tree->size_x,_tree->size_l);
        enc+=str;
    }

    return enc;

}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x68(%rsp), %rdi
callq 0x4420
leaq 0x38(%rsp), %r15
movq %r15, -0x10(%r15)
xorl %eax, %eax
movq %rax, -0x8(%r15)
movb %al, (%r15)
leaq 0x58(%rsp), %r12
movq %r12, -0x10(%r12)
movq %rax, -0x8(%r12)
movb %al, (%r12)
movq 0x40(%r14), %rax
testq %rax, %rax
jne 0x13305
movq 0x9d4d(%rip), %rdi      # 0x1cff0
leaq 0x3932(%rip), %rsi      # 0x16bdc
movl $0x31, %edx
callq 0x4340
leaq 0x18(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x3dca(%rip), %rsi      # 0x1708e
leaq 0x3dce(%rip), %rdx      # 0x17099
leaq 0x8(%rsp), %rdi
callq 0x6c96
leaq 0x4(%rsp), %rsi
movl $0xd0, (%rsi)
leaq 0x8(%rsp), %rdi
callq 0xcde4
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x13301
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42e0
movq 0x40(%r14), %rax
cmpl $0x0, 0x24(%rax)
je 0x13467
movq $0x0, 0x28(%rax)
movq 0x40(%r14), %rax
xorl %ecx, %ecx
movl %ecx, 0x40(%rax)
movl %ecx, 0x38(%rax)
movb $0x0, 0x3c(%rax)
movq 0x40(%r14), %rax
movl 0x20(%rax), %ecx
andl $-0x4, %ecx
incl %ecx
movw %cx, 0x20(%rax)
movq 0x40(%r14), %rax
movl 0x20(%rax), %ecx
movl 0x24(%rax), %edx
movl %ecx, %esi
shll $0x6, %esi
andl $0x4, %ecx
leal (%rsi,%rcx,8), %ecx
andl $0x1f, %edx
orl %ecx, %edx
movb %dl, 0x28(%rax)
movq 0x40(%r14), %rdx
movl $0x1, 0x2c(%rdx)
movl 0x24(%rdx), %eax
cmpl $0x1f, %eax
jb 0x134b3
cmpl $0x4000000, %eax        # imm = 0x4000000
jb 0x133ee
movq 0x9c77(%rip), %rdi      # 0x1cff0
leaq 0x3d73(%rip), %rsi      # 0x170f3
movl $0x23, %edx
callq 0x4340
movq 0x40(%r14), %rax
movl 0x24(%rax), %esi
movq 0x9c58(%rip), %rdi      # 0x1cff0
callq 0x4560
leaq 0x18(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x3ce1(%rip), %rsi      # 0x1708e
leaq 0x3ce5(%rip), %rdx      # 0x17099
leaq 0x8(%rsp), %rdi
callq 0x6c96
leaq 0x4(%rsp), %rsi
movl $0xee, (%rsi)
leaq 0x8(%rsp), %rdi
callq 0xcde4
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x133ea
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42e0
movq 0x40(%r14), %rdx
movl 0x20(%rdx), %eax
movl %eax, %ecx
shll $0x6, %ecx
andl $0x4, %eax
leal (%rcx,%rax,8), %eax
orb $0x1f, %al
movb %al, 0x28(%rdx)
movq 0x40(%r14), %rdx
movslq 0x24(%rdx), %rcx
testq %rcx, %rcx
je 0x134a0
movl $0x1, %eax
xorl %edx, %edx
movq %rdx, %rsi
movq 0x40(%r14), %rdi
movl %esi, %r8d
movb 0x28(%rdi,%r8), %r8b
movb %r8b, 0x29(%rdi,%rsi)
leaq -0x1(%rsi), %rdi
incq %rsi
cmpq $0x1, %rsi
movq %rdi, %rsi
jg 0x1341c
incq %rax
movl %ecx, %esi
orb $-0x80, %sil
movq 0x40(%r14), %rdi
movb %sil, 0x29(%rdi)
movq %rcx, %rsi
sarq $0x7, %rsi
incq %rdx
cmpq $0x7f, %rcx
movq %rsi, %rcx
ja 0x13419
movq 0x40(%r14), %rdx
jmp 0x134a5
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
leaq 0x359b(%rip), %rdx      # 0x16a10
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x6c96
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x1366d
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42e0
jmp 0x1366d
movl $0x1, %eax
cltq
andb $0x7f, 0x27(%rax,%rdx)
movq 0x40(%r14), %rdx
movl %eax, 0x2c(%rdx)
movq 0x30(%rdx), %rcx
cmpq $0x80, %rcx
jae 0x134c7
movl $0x1, %eax
jmp 0x1351b
movl $0x1, %eax
xorl %edx, %edx
movq %rdx, %rsi
movq 0x40(%r14), %rdi
movl %esi, %r8d
movb 0x38(%rdi,%r8), %r8b
movb %r8b, 0x39(%rdi,%rsi)
leaq -0x1(%rsi), %rdi
incq %rsi
cmpq $0x1, %rsi
movq %rdi, %rsi
jg 0x134d1
incq %rax
movq 0x40(%r14), %rsi
movb %cl, 0x39(%rsi)
movq %rcx, %rsi
sarq $0x8, %rsi
incq %rdx
cmpq $0xff, %rcx
movq %rsi, %rcx
ja 0x134ce
movl %eax, %ecx
addb $0x7f, %cl
movq 0x40(%r14), %rdx
movb %cl, 0x38(%rdx)
movq 0x40(%r14), %rdx
movl %eax, 0x40(%rdx)
leaq 0x28(%rdx), %rcx
testb $0x4, 0x20(%rdx)
movslq 0x2c(%rdx), %r8
movq 0x30(%rsp), %rdx
jne 0x135ed
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0x44c0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0x48(%rsp), %rdi
callq 0x40f0
movq 0x40(%r14), %rcx
movslq 0x40(%rcx), %r8
addq $0x38, %rcx
leaq 0x28(%rsp), %rdi
movq 0x8(%rdi), %rdx
xorl %esi, %esi
callq 0x44c0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0x48(%rsp), %rdi
callq 0x40f0
movq 0x40(%r14), %rax
movl 0x20(%rax), %eax
shrl $0x3, %eax
andl $0x1f, %eax
leaq 0x4(%rsp), %rsi
movl %eax, (%rsi)
leaq 0xa361(%rip), %rdi      # 0x1d908
callq 0x1285a
movq 0x40(%r14), %rcx
movq 0x48(%rcx), %rsi
leaq 0x8(%rsp), %rdi
callq *0x8(%rax)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x48(%rsp), %rdi
callq 0x40f0
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1363d
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42e0
jmp 0x1363d
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0x44c0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0x48(%rsp), %rdi
callq 0x40f0
movq 0x40(%r14), %rcx
movslq 0x40(%rcx), %r8
addq $0x38, %rcx
leaq 0x28(%rsp), %rdi
movq 0x8(%rdi), %rdx
xorl %esi, %esi
callq 0x44c0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0x48(%rsp), %rdi
callq 0x40f0
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0x48(%rsp), %rcx
cmpq %r12, %rcx
je 0x1365c
movq %rcx, (%rbx)
movq 0x58(%rsp), %rax
movq %rax, 0x10(%rbx)
jmp 0x13664
movups (%r12), %xmm0
movups %xmm0, (%rax)
movq 0x50(%rsp), %rax
movq %rax, 0x8(%rbx)
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x13684
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42e0
movq 0x9935(%rip), %rsi      # 0x1cfc0
leaq 0x68(%rsp), %rdi
callq 0x4170
leaq 0xd8(%rsp), %rdi
callq 0x4100
movq %rbx, %rax
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
jmp 0x136cd
jmp 0x136ef
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x136da
jmp 0x136f2
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x136f2
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42e0
jmp 0x136f2
jmp 0x136ef
jmp 0x136ef
jmp 0x136ef
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x13709
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42e0
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x13720
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42e0
movq 0x9899(%rip), %rsi      # 0x1cfc0
leaq 0x68(%rsp), %rdi
callq 0x4170
leaq 0xd8(%rsp), %rdi
callq 0x4100
movq %rbx, %rdi
callq 0x4590