// File: /workspace/github_cpp_makefile_star2_O1/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)
cmpq %rax, 0x40(%r14)
jne 0x13a6a
movq 0x95e4(%rip), %rdi      # 0x1cff0
leaq 0x31c9(%rip), %rsi      # 0x16bdc
movl $0x31, %edx
callq 0x4340
leaq 0x18(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x3661(%rip), %rsi      # 0x1708e
leaq 0x3665(%rip), %rdx      # 0x17099
leaq 0x8(%rsp), %rdi
callq 0x6e3c
leaq 0x4(%rsp), %rsi
movl $0xd0, (%rsi)
leaq 0x8(%rsp), %rdi
callq 0xd138
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x13a6a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42e0
movq 0x40(%r14), %rax
cmpl $0x0, 0x24(%rax)
je 0x13bc9
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), %rax
movl $0x1, 0x2c(%rax)
movl 0x24(%rax), %eax
cmpl $0x1f, %eax
jb 0x13bfe
cmpl $0x4000000, %eax        # imm = 0x4000000
jb 0x13b53
movq 0x950e(%rip), %rdi      # 0x1cff0
leaq 0x363c(%rip), %rsi      # 0x17125
movl $0x23, %edx
callq 0x4340
movq 0x40(%r14), %rax
movl 0x24(%rax), %esi
movq 0x94ef(%rip), %rdi      # 0x1cff0
callq 0x4560
leaq 0x18(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x3578(%rip), %rsi      # 0x1708e
leaq 0x357c(%rip), %rdx      # 0x17099
leaq 0x8(%rsp), %rdi
callq 0x6e3c
leaq 0x4(%rsp), %rsi
movl $0xee, (%rsi)
leaq 0x8(%rsp), %rdi
callq 0xd138
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x13b53
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42e0
movq 0x40(%r14), %rax
movl 0x20(%rax), %ecx
movl %ecx, %edx
shll $0x6, %edx
andl $0x4, %ecx
leal (%rdx,%rcx,8), %ecx
orb $0x1f, %cl
movb %cl, 0x28(%rax)
movq 0x40(%r14), %rax
movslq 0x24(%rax), %rcx
testq %rcx, %rcx
je 0x13be7
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 0x13b82
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 0x13b7f
jmp 0x13bec
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
leaq 0x2e39(%rip), %rdx      # 0x16a10
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x6e3c
jmp 0x13dcf
movl $0x1, %eax
movq 0x40(%r14), %rcx
cltq
andb $0x7f, 0x27(%rax,%rcx)
movq 0x40(%r14), %rcx
movl %eax, 0x2c(%rcx)
movq 0x40(%r14), %rdx
movq 0x30(%rdx), %rcx
cmpq $0x80, %rcx
jae 0x13c16
movl $0x1, %eax
jmp 0x13c6a
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 0x13c20
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 0x13c1d
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 0x13d3c
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 0x9c12(%rip), %rdi      # 0x1d908
callq 0x12f44
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 0x13d8c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42e0
jmp 0x13d8c
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 0x13dab
movq %rcx, (%rbx)
movq 0x58(%rsp), %rax
movq %rax, 0x10(%rbx)
jmp 0x13db3
movups (%r12), %xmm0
movups %xmm0, (%rax)
movq 0x50(%rsp), %rax
movq %rax, 0x8(%rbx)
movq %r12, 0x48(%rsp)
movq $0x0, 0x50(%rsp)
movb $0x0, 0x58(%rsp)
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x13de6
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42e0
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x13dfd
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42e0
movq 0x91bc(%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 0x13e46
jmp 0x13e68
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x13e53
jmp 0x13e6b
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x13e6b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42e0
jmp 0x13e6b
jmp 0x13e68
jmp 0x13e68
jmp 0x13e68
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x13e82
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42e0
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x13e99
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42e0
movq 0x9120(%rip), %rsi      # 0x1cfc0
leaq 0x68(%rsp), %rdi
callq 0x4170
leaq 0xd8(%rsp), %rdi
callq 0x4100
movq %rbx, %rdi
callq 0x4590
nop