// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x68(%rsp), %rdi
callq 0x4400
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
andq $0x0, -0x8(%r15)
movb %cl, (%rax)
movb %cl, (%r15)
movq 0x40(%r14), %rax
testq %rax, %rax
jne 0xfefe
movq 0xa137(%rip), %rdi      # 0x19ff0
leaq 0x2d1c(%rip), %rsi      # 0x12bdc
callq 0x4290
leaq 0x31c2(%rip), %rsi      # 0x1308e
leaq 0x28(%rsp), %rdi
leaq 0x3(%rsp), %rdx
callq 0x5caa
leaq 0x4(%rsp), %rsi
movl $0xd0, (%rsi)
leaq 0x28(%rsp), %rdi
callq 0xb17a
leaq 0x28(%rsp), %rdi
callq 0x4150
movq 0x40(%r14), %rax
cmpl $0x0, 0x24(%rax)
je 0x10021
andq $0x0, 0x28(%rax)
movq 0x40(%r14), %rax
andl $0x0, 0x40(%rax)
andl $0x0, 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 0x10050
cmpl $0x4000000, %eax        # imm = 0x4000000
jb 0xffc3
movq 0xa081(%rip), %rdi      # 0x19ff0
leaq 0x317d(%rip), %rsi      # 0x130f3
callq 0x4290
movq 0x40(%r14), %rcx
movl 0x24(%rcx), %esi
movq %rax, %rdi
callq 0x4540
leaq 0x30fd(%rip), %rsi      # 0x1308e
leaq 0x28(%rsp), %rdi
leaq 0x3(%rsp), %rdx
callq 0x5caa
leaq 0x4(%rsp), %rsi
movl $0xee, (%rsi)
leaq 0x28(%rsp), %rdi
callq 0xb17a
leaq 0x28(%rsp), %rdi
callq 0x4150
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), %rax
movslq 0x24(%rax), %rcx
pushq $0x1
popq %rax
pushq $0x29
popq %rdx
testq %rcx, %rcx
je 0x1003a
movq %rdx, %rsi
leaq -0x28(%rsi), %rdi
testq %rdi, %rdi
jle 0x10007
movq 0x40(%r14), %rdi
movb -0x1(%rdi,%rsi), %r8b
movb %r8b, (%rdi,%rsi)
decq %rsi
jmp 0xffec
incq %rax
movl %ecx, %esi
orb $-0x80, %sil
movq 0x40(%r14), %rdi
movb %sil, 0x29(%rdi)
sarq $0x7, %rcx
incq %rdx
jmp 0xffe4
leaq 0x29e8(%rip), %rsi      # 0x12a10
leaq 0x28(%rsp), %rdx
movq %rbx, %rdi
callq 0x5caa
jmp 0x101c7
movq 0x40(%r14), %rcx
leal -0x1(%rax), %edx
movslq %edx, %rdx
andb $0x7f, 0x28(%rcx,%rdx)
movq 0x40(%r14), %rdx
movl %eax, 0x2c(%rdx)
movq 0x30(%rdx), %rax
cmpq $0x80, %rax
jae 0x10061
pushq $0x1
popq %rcx
jmp 0x100a5
pushq $0x1
popq %rcx
pushq $0x39
popq %rdx
testq %rax, %rax
je 0x1009d
movq %rdx, %rsi
leaq -0x38(%rsi), %rdi
testq %rdi, %rdi
jle 0x1008a
movq 0x40(%r14), %rdi
movb -0x1(%rdi,%rsi), %r8b
movb %r8b, (%rdi,%rsi)
decq %rsi
jmp 0x1006f
incq %rcx
movq 0x40(%r14), %rsi
movb %al, 0x39(%rsi)
sarq $0x8, %rax
incq %rdx
jmp 0x10067
movl %ecx, %eax
addb $0x7f, %al
movq 0x40(%r14), %rdx
movb %al, 0x38(%rdx)
movq 0x40(%r14), %rax
movl %ecx, 0x40(%rax)
leaq 0x28(%rax), %rsi
testb $0x4, 0x20(%rax)
movslq 0x2c(%rax), %rdx
jne 0x1014a
leaq 0x48(%rsp), %rdi
callq 0x43f0
leaq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x45d0
movq 0x40(%r14), %rsi
movslq 0x40(%rsi), %rdx
addq $0x38, %rsi
leaq 0x48(%rsp), %rdi
callq 0x43f0
leaq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x45d0
movq 0x40(%r14), %rax
movl 0x20(%rax), %eax
shrl $0x3, %eax
andl $0x1f, %eax
leaq 0x4(%rsp), %rsi
movl %eax, (%rsi)
leaq 0xa7ee(%rip), %rdi      # 0x1a908
callq 0xf4aa
movq 0x40(%r14), %rcx
movq 0x48(%rcx), %rsi
leaq 0x28(%rsp), %rdi
callq *0x8(%rax)
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x45d0
leaq 0x28(%rsp), %rdi
callq 0x4150
jmp 0x10188
leaq 0x48(%rsp), %rdi
callq 0x43f0
leaq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x45d0
movq 0x40(%r14), %rsi
movslq 0x40(%rsi), %rdx
addq $0x38, %rsi
leaq 0x48(%rsp), %rdi
callq 0x43f0
leaq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x45d0
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0x8(%rsp), %rcx
cmpq %r15, %rcx
je 0x101a7
movq %rcx, (%rbx)
movq 0x18(%rsp), %rax
movq %rax, 0x10(%rbx)
jmp 0x101ae
movups (%r15), %xmm0
movups %xmm0, (%rax)
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rbx)
movq %r15, 0x8(%rsp)
andq $0x0, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x4150
leaq 0x48(%rsp), %rdi
callq 0x4150
leaq 0x68(%rsp), %rdi
callq 0x40a0
movq %rbx, %rax
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbx
popq %r14
popq %r15
retq
jmp 0x101fb
jmp 0x10210
jmp 0x101fb
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x4150
jmp 0x10213
jmp 0x10210
jmp 0x10210
jmp 0x10210
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x4150
leaq 0x48(%rsp), %rdi
callq 0x4150
leaq 0x68(%rsp), %rdi
callq 0x40a0
movq %rbx, %rdi
callq 0x4560
nop