// File: 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 %rbp
movq %rsp, %rbp
subq $0x2b0, %rsp            # imm = 0x2B0
movq %rdi, -0x288(%rbp)
movq %rdi, %rax
movq %rax, -0x280(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x278(%rbp)
movl $0x1, -0x24(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x4540
leaq -0x1c0(%rbp), %rdi
callq 0x4570
leaq -0x1e0(%rbp), %rdi
callq 0x4570
movq -0x278(%rbp), %rax
cmpq $0x0, 0x40(%rax)
jne 0x21846
movq 0xf872(%rip), %rdi      # 0x30fe8
leaq 0x453d(%rip), %rsi      # 0x25cba
callq 0x4340
jmp 0x21784
leaq -0x211(%rbp), %rdi
movq %rdi, -0x290(%rbp)
callq 0x46e0
movq -0x290(%rbp), %rdx
leaq 0x49c7(%rip), %rsi      # 0x2616c
leaq -0x210(%rbp), %rdi
callq 0x7670
jmp 0x217b3
movl $0xd0, -0x218(%rbp)
leaq -0x210(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x151c0
jmp 0x217d2
leaq -0x210(%rbp), %rdi
callq 0x41e0
leaq -0x211(%rbp), %rdi
callq 0x43d0
jmp 0x21846
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1e8(%rbp)
movl %eax, -0x1ec(%rbp)
jmp 0x21e71
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1e8(%rbp)
movl %eax, -0x1ec(%rbp)
jmp 0x21835
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1e8(%rbp)
movl %eax, -0x1ec(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x41e0
leaq -0x211(%rbp), %rdi
callq 0x43d0
jmp 0x21e71
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0x24(%rax)
jne 0x218c4
leaq -0x219(%rbp), %rdi
movq %rdi, -0x298(%rbp)
callq 0x46e0
movq -0x288(%rbp), %rdi
movq -0x298(%rbp), %rdx
leaq 0x426f(%rip), %rsi      # 0x25aee
callq 0x7670
jmp 0x21886
leaq -0x219(%rbp), %rdi
callq 0x43d0
movl $0x1, -0x220(%rbp)
jmp 0x21e3d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1e8(%rbp)
movl %eax, -0x1ec(%rbp)
leaq -0x219(%rbp), %rdi
callq 0x43d0
jmp 0x21e71
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rcx
movl $0x0, 0x2c(%rcx)
movq 0x40(%rax), %rdi
addq $0x28, %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x41c0
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rcx
movl $0x0, 0x40(%rcx)
movq 0x40(%rax), %rdi
addq $0x38, %rdi
xorl %esi, %esi
movl $0x5, %edx
callq 0x41c0
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rcx
movw 0x20(%rcx), %dx
andw $-0x4, %dx
orw $0x1, %dx
movw %dx, 0x20(%rcx)
movq 0x40(%rax), %rcx
movw 0x20(%rcx), %cx
andw $0x3, %cx
movzwl %cx, %ecx
shll $0x6, %ecx
movq 0x40(%rax), %rdx
movw 0x20(%rdx), %dx
shrw $0x2, %dx
andw $0x1, %dx
movzwl %dx, %edx
shll $0x5, %edx
addl %edx, %ecx
movq 0x40(%rax), %rdx
movl 0x24(%rdx), %edx
andl $0x1f, %edx
addl %edx, %ecx
movb %cl, %dl
movq 0x40(%rax), %rcx
movb %dl, 0x28(%rcx)
movq 0x40(%rax), %rcx
movl $0x1, 0x2c(%rcx)
movq 0x40(%rax), %rax
movl 0x24(%rax), %eax
sarl $0x5, %eax
cmpl $0x0, %eax
jne 0x21999
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rax
cmpl $0x1f, 0x24(%rax)
jne 0x21b7f
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rax
movl 0x24(%rax), %eax
sarl $0x1a, %eax
cmpl $0x0, %eax
je 0x21a96
movq 0xf62e(%rip), %rdi      # 0x30fe8
leaq 0x4842(%rip), %rsi      # 0x26203
callq 0x4340
movq %rax, -0x2a0(%rbp)
jmp 0x219cf
movq -0x2a0(%rbp), %rdi
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rax
movl 0x24(%rax), %esi
callq 0x46a0
jmp 0x219eb
leaq -0x241(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x46e0
movq -0x2a8(%rbp), %rdx
leaq 0x4760(%rip), %rsi      # 0x2616c
leaq -0x240(%rbp), %rdi
callq 0x7670
jmp 0x21a1a
movl $0xee, -0x248(%rbp)
leaq -0x240(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x151c0
jmp 0x21a39
leaq -0x240(%rbp), %rdi
callq 0x41e0
leaq -0x241(%rbp), %rdi
callq 0x43d0
jmp 0x21a96
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1e8(%rbp)
movl %eax, -0x1ec(%rbp)
jmp 0x21a85
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1e8(%rbp)
movl %eax, -0x1ec(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x41e0
leaq -0x241(%rbp), %rdi
callq 0x43d0
jmp 0x21e71
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rcx
movw 0x20(%rcx), %cx
andw $0x3, %cx
movzwl %cx, %ecx
shll $0x6, %ecx
movq 0x40(%rax), %rdx
movw 0x20(%rdx), %dx
shrw $0x2, %dx
andw $0x1, %dx
movzwl %dx, %edx
shll $0x5, %edx
addl %edx, %ecx
addl $0x1f, %ecx
movb %cl, %dl
movq 0x40(%rax), %rcx
movb %dl, 0x28(%rcx)
movq 0x40(%rax), %rax
movslq 0x24(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x21b54
movl -0x24(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x24(%rbp)
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jle 0x21b29
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rcx
movl -0x28(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movb 0x28(%rcx,%rdx), %dl
movq 0x40(%rax), %rax
movslq -0x28(%rbp), %rcx
movb %dl, 0x28(%rax,%rcx)
movl -0x28(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x21af4
movq -0x278(%rbp), %rax
movq -0x20(%rbp), %rcx
andq $0x7f, %rcx
addq $0x80, %rcx
movq 0x40(%rax), %rax
movb %cl, 0x29(%rax)
movq -0x20(%rbp), %rax
sarq $0x7, %rax
movq %rax, -0x20(%rbp)
jmp 0x21adf
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rcx
movl -0x24(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movzbl 0x28(%rcx,%rdx), %esi
andl $0x7f, %esi
movb %sil, 0x28(%rcx,%rdx)
movl -0x24(%rbp), %ecx
movq 0x40(%rax), %rax
movl %ecx, 0x2c(%rax)
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x30(%rax), %rax
sarq $0x7, %rax
cmpq $0x0, %rax
je 0x21c51
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x30(%rax), %rax
movq %rax, -0x20(%rbp)
movl $0x1, -0x24(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x21c29
movl -0x24(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x24(%rbp)
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jle 0x21c00
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rcx
movl -0x28(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movb 0x38(%rcx,%rdx), %dl
movq 0x40(%rax), %rax
movslq -0x28(%rbp), %rcx
movb %dl, 0x38(%rax,%rcx)
movl -0x28(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x21bcb
movq -0x278(%rbp), %rax
movq -0x20(%rbp), %rcx
movzbl %cl, %ecx
andl $0xff, %ecx
movq 0x40(%rax), %rax
movb %cl, 0x39(%rax)
movq -0x20(%rbp), %rax
sarq $0x8, %rax
movq %rax, -0x20(%rbp)
jmp 0x21bb6
movq -0x278(%rbp), %rax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
addl $0x80, %ecx
movb %cl, %dl
movq 0x40(%rax), %rcx
movb %dl, 0x38(%rcx)
movl -0x24(%rbp), %ecx
movq 0x40(%rax), %rax
movl %ecx, 0x40(%rax)
jmp 0x21c74
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rcx
movq 0x30(%rcx), %rcx
movb %cl, %dl
movq 0x40(%rax), %rcx
movb %dl, 0x38(%rcx)
movq 0x40(%rax), %rax
movl $0x1, 0x40(%rax)
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rax
movw 0x20(%rax), %ax
shrw $0x2, %ax
andw $0x1, %ax
cmpw $0x0, %ax
jne 0x21dac
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, %rsi
addq $0x28, %rsi
movslq 0x2c(%rax), %rdx
leaq -0x1c0(%rbp), %rdi
callq 0x4530
jmp 0x21cb9
leaq -0x1e0(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x44d0
jmp 0x21cce
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, %rsi
addq $0x38, %rsi
movslq 0x40(%rax), %rdx
leaq -0x1c0(%rbp), %rdi
callq 0x4530
jmp 0x21cf2
leaq -0x1e0(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x44d0
jmp 0x21d07
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rax
movzwl 0x20(%rax), %eax
shrl $0x3, %eax
andl $0x1f, %eax
movl %eax, -0x26c(%rbp)
leaq 0xfccf(%rip), %rdi      # 0x319f8
leaq -0x26c(%rbp), %rsi
callq 0x1ef70
movq %rax, -0x2b0(%rbp)
jmp 0x21d3e
movq -0x278(%rbp), %rcx
movq -0x2b0(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x40(%rcx), %rcx
movq 0x48(%rcx), %rsi
leaq -0x268(%rbp), %rdi
callq *%rax
jmp 0x21d63
leaq -0x1e0(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x44d0
jmp 0x21d78
leaq -0x268(%rbp), %rdi
callq 0x41e0
jmp 0x21e20
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1e8(%rbp)
movl %eax, -0x1ec(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x41e0
jmp 0x21e71
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, %rsi
addq $0x28, %rsi
movslq 0x2c(%rax), %rdx
leaq -0x1c0(%rbp), %rdi
callq 0x4530
jmp 0x21dd0
leaq -0x1e0(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x44d0
jmp 0x21de5
movq -0x278(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, %rsi
addq $0x38, %rsi
movslq 0x40(%rax), %rdx
leaq -0x1c0(%rbp), %rdi
callq 0x4530
jmp 0x21e09
leaq -0x1e0(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x44d0
jmp 0x21e1e
jmp 0x21e20
movq -0x288(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x41d0
movl $0x1, -0x220(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x41e0
leaq -0x1c0(%rbp), %rdi
callq 0x41e0
leaq -0x1a0(%rbp), %rdi
callq 0x40c0
movq -0x280(%rbp), %rax
addq $0x2b0, %rsp            # imm = 0x2B0
popq %rbp
retq
leaq -0x1e0(%rbp), %rdi
callq 0x41e0
leaq -0x1c0(%rbp), %rdi
callq 0x41e0
leaq -0x1a0(%rbp), %rdi
callq 0x40c0
movq -0x1e8(%rbp), %rdi
callq 0x46d0
nopw %cs:(%rax,%rax)