// File: /workspace/github_cpp_makefile_star2_O1/tap3edit[P]tap3xml/TapInfo.cpp
// Function: TapInfo::buffin(Buffin*)
void TapInfo::buffin(Buffin *bfin)
{
    string str;
    int pos, bfin_pos, i;

    _bfin=bfin;
    bfin_pos=_bfin->get_pos();
    _bfin->set_pos(0);
    _bfin->read(_bfin->get_end() > 500 ? 500 : _bfin->get_end());

    str=bcd2hexa(_bfin->get_buf());


    /* 1. Find out which kind of file it is */

    pair<string, string> types[] =
    {
        pair<string,string>("",        "ERR"),    /* Not recognized file */
        pair<string,string>("61",      "TAP"),    /* Tap file */
        pair<string,string>("62",      "TAP"),    /* Notification file */
        pair<string,string>("7f8416",  "RAP"),    /* Rap file */
        pair<string,string>("7f8417",  "ACK")    /* Acknowledgment file */
    };

    for(i=0;i<5;i++)
    {
        if (str.substr(0,types[i].first.size())==types[i].first)
        {
            _type=types[i].second;
        }
    }


    /* 2. Find its version */

    pair<string, int *> version[] =
    {
        pair<string,int *>("5f814901",  &_version),
        pair<string,int *>("5f813d01",  &_release),
        pair<string,int *>("5f842001",  &_suplversion),
        pair<string,int *>("5f841f01",  &_suplrelease)
    };

    if (_type=="ACK" )
    {
        _version=1;
        _release=1;
        _suplversion=3;
        _suplrelease=1;
        _type="RAP";
    }
    else
    {
        for(i=0;i<4;i++)
        {
            if ((pos=str.find(version[i].first)) != (int)string::npos)
            {
                *(version[i].second)=atoi(bcd2dec(hexa2bcd(str.substr(pos+version[i].first.size(),2))).c_str());
            }
            else
            {
                *(version[i].second)=-1;
            }
        }

        if (_type=="RAP")
        {
            i=_version;
            _version=_suplversion;
            _suplversion=i;

            i=_release;
            _release=_suplrelease;
            _suplrelease=i;

            if ( _suplversion < 0 )
                _suplversion=3;

            if ( _suplrelease < 0 )
                _suplrelease=1;

        }

        if (_version<0 || _release<0)
            _type="ERR";

    }

    _bfin->set_pos(bfin_pos);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2a8, %rsp            # imm = 0x2A8
movq %rdi, %r12
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq %rsi, (%rdi)
movq %rsi, %rdi
callq 0xecfe
movq %rax, %rbx
movq (%r12), %rdi
leaq 0x160(%rsp), %rsi
movq $0x0, (%rsi)
callq 0xed06
movq (%r12), %r14
movq %r14, %rdi
callq 0xee3e
movl $0x1f4, %esi            # imm = 0x1F4
cmpq $0x1f4, %rax            # imm = 0x1F4
jg 0x795d
movq (%r12), %rdi
callq 0xee3e
movq %rax, %rsi
movq %r14, %rdi
callq 0xee46
movq (%r12), %rsi
leaq 0xa0(%rsp), %rdi
callq 0xefca
leaq 0x160(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0xd4c6
movq %rbx, 0x58(%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x160(%rsp), %r14
movq %r14, %rsi
callq 0x43a0
movq (%r14), %rdi
leaq 0x170(%rsp), %rax
cmpq %rax, %rdi
je 0x79c5
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x42e0
leaq 0xb0(%rsp), %rbx
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
je 0x79e6
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x42e0
leaq 0x100c3(%rip), %rsi     # 0x17ab0
leaq 0xe788(%rip), %rdx      # 0x1617c
movq %r14, %r15
movq %r14, %rdi
callq 0x84ac
leaq 0x1a0(%rsp), %r15
leaq 0xe894(%rip), %rsi      # 0x162a2
leaq 0xe796(%rip), %rdx      # 0x161ab
movq %r15, %rdi
callq 0x852a
leaq 0x1e0(%rsp), %r15
leaq 0xe879(%rip), %rsi      # 0x162a5
leaq 0xe778(%rip), %rdx      # 0x161ab
movq %r15, %rdi
callq 0x852a
leaq 0x220(%rsp), %r15
leaq 0xe85e(%rip), %rsi      # 0x162a8
leaq 0xe756(%rip), %rdx      # 0x161a7
movq %r15, %rdi
callq 0x85a8
leaq 0x260(%rsp), %r15
leaq 0xe847(%rip), %rsi      # 0x162af
leaq 0xe847(%rip), %rdx      # 0x162b6
movq %r15, %rdi
callq 0x85a8
movq %r12, 0x20(%rsp)
leaq 0x18(%r12), %rax
movq %rax, 0x8(%rsp)
movl $0x5, %r12d
leaq 0x180(%rsp), %r14
leaq 0xa0(%rsp), %r15
leaq 0x28(%rsp), %rbp
movq -0x18(%r14), %rcx
movq %r15, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x4300
movq 0xa8(%rsp), %rdx
cmpq -0x18(%r14), %rdx
jne 0x7ade
testq %rdx, %rdx
je 0x7ae3
movq -0x20(%r14), %rsi
movq 0xa0(%rsp), %rdi
callq 0x42f0
testl %eax, %eax
sete %r13b
jmp 0x7ae6
xorl %r13d, %r13d
jmp 0x7ae6
movb $0x1, %r13b
movq 0xa0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x7b03
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x42e0
testb %r13b, %r13b
je 0x7b15
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x4180
addq $0x40, %r14
decq %r12
jne 0x7aa1
leaq 0xa0(%rsp), %rbp
movq %rbx, (%rbp)
leaq 0xe789(%rip), %rsi      # 0x162ba
leaq 0xe78a(%rip), %rdx      # 0x162c2
movq %rbp, %rdi
callq 0x7296
movq 0x20(%rsp), %rbx
leaq 0x8(%rbx), %r12
leaq 0xc8(%rsp), %r14
movq %r12, -0x8(%r14)
leaq 0xd8(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0xe75b(%rip), %rsi      # 0x162c3
leaq 0xe75c(%rip), %rdx      # 0x162cb
movq %r14, %rdi
callq 0x7296
leaq 0x10(%rbx), %r13
leaq 0xf0(%rsp), %r14
movq %r13, -0x8(%r14)
leaq 0x100(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0xe732(%rip), %rsi      # 0x162cc
leaq 0xe733(%rip), %rdx      # 0x162d4
movq %r14, %rdi
callq 0x7296
leaq 0xc(%rbx), %rax
leaq 0x118(%rsp), %r14
movq %rax, 0x18(%rsp)
movq %rax, -0x8(%r14)
leaq 0x128(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xe704(%rip), %rsi      # 0x162d5
leaq 0xe705(%rip), %rdx      # 0x162dd
movq %r14, %rdi
callq 0x7296
leaq 0x14(%rbx), %r14
movq %r14, 0x138(%rsp)
leaq 0xe6c3(%rip), %rsi      # 0x162b6
movq 0x8(%rsp), %rdi
callq 0x40d0
testl %eax, %eax
je 0x7d8f
movq %r14, 0x10(%rsp)
movq %r13, 0x48(%rsp)
movq %r12, 0x50(%rsp)
movl $0x20, %r12d
leaq 0x28(%rsp), %r13
leaq 0x60(%rsp), %rbp
leaq 0x80(%rsp), %r14
movq 0x80(%rsp,%r12), %rsi
movq 0x88(%rsp,%r12), %rcx
movq %r13, %rdi
xorl %edx, %edx
callq 0x4580
cmpl $-0x1, %eax
jne 0x7c5e
movq 0xa0(%rsp,%r12), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
jmp 0x7d0f
movslq %eax, %rdx
addq 0x88(%rsp,%r12), %rdx
movl $0x2, %ecx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x4300
movq %r14, %rdi
movq %rbp, %rsi
callq 0xd5db
leaq 0x140(%rsp), %rdi
movq %r14, %rsi
callq 0xd1fc
movq 0x140(%rsp), %rbx
movq %rbx, %rdi
callq 0x44d0
movq 0xa0(%rsp,%r12), %rcx
movl %eax, (%rcx)
leaq 0x150(%rsp), %rax
cmpq %rax, %rbx
je 0x7cce
movq 0x150(%rsp), %rsi
incq %rsi
movq %rbx, %rdi
callq 0x42e0
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x7cf3
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x42e0
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x7d0f
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x42e0
addq $0x28, %r12
cmpq $0xc0, %r12
jne 0x7c2c
leaq 0xe480(%rip), %rsi      # 0x161a7
movq 0x8(%rsp), %rdi
callq 0x40d0
testl %eax, %eax
movq 0x20(%rsp), %rbx
movq 0x50(%rsp), %rsi
movq 0x48(%rsp), %rdi
jne 0x7d7c
movl (%rsi), %ecx
movq 0x18(%rsp), %r8
movl (%r8), %eax
movl %eax, (%rsi)
movl %ecx, (%r8)
movl (%rdi), %eax
movq 0x10(%rsp), %r9
movl (%r9), %edx
movl %edx, (%rdi)
movl %eax, (%r9)
testl %ecx, %ecx
jns 0x7d6d
movl $0x3, (%r8)
testl %eax, %eax
jns 0x7d7c
movq 0x10(%rsp), %rax
movl $0x1, (%rax)
cmpl $0x0, (%rsi)
js 0x7db3
cmpl $0x0, (%rdi)
leaq 0xe3f1(%rip), %rcx      # 0x1617c
jns 0x7dd0
jmp 0x7dba
movl $0x1, %eax
movl %eax, (%r12)
movl %eax, (%r13)
movq 0x18(%rsp), %rcx
movl $0x3, (%rcx)
movl %eax, (%r14)
leaq 0xe3f6(%rip), %rcx      # 0x161a7
jmp 0x7dba
leaq 0xe3c2(%rip), %rcx      # 0x1617c
movq 0x20(%rbx), %rdx
movl $0x3, %r8d
movq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x44c0
movq (%rbx), %rdi
movslq 0x58(%rsp), %rax
leaq 0x140(%rsp), %rsi
movq %rax, (%rsi)
callq 0xed06
movq $-0xa0, %rbx
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x7e03
movq (%r15), %rsi
incq %rsi
callq 0x42e0
addq $-0x28, %r15
addq $0x28, %rbx
jne 0x7def
movq $-0x140, %rbx           # imm = 0xFEC0
leaq 0x290(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x7e30
movq (%r14), %rsi
incq %rsi
callq 0x42e0
movq -0x30(%r14), %rdi
leaq -0x20(%r14), %rax
cmpq %rdi, %rax
je 0x7e48
movq (%rax), %rsi
incq %rsi
callq 0x42e0
addq $-0x40, %r14
addq $0x40, %rbx
jne 0x7e1c
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x7e6e
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42e0
addq $0x2a8, %rsp            # imm = 0x2A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7f38
jmp 0x7f38
jmp 0x7e8e
jmp 0x7e8e
movq %rax, %rbx
jmp 0x7e99
movq %rax, %rbx
movq %rbp, %r14
cmpq %r14, %rbp
je 0x7fb4
leaq 0xa0(%rsp), %r15
movq -0x28(%r14), %rdi
leaq -0x18(%r14), %rax
cmpq %rdi, %rax
je 0x7ec2
movq (%rax), %rsi
incq %rsi
callq 0x42e0
addq $-0x28, %r14
cmpq %r15, %r14
jne 0x7eaa
jmp 0x7fb4
movq %rax, %rbx
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7fd4
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x42e0
jmp 0x7fd4
jmp 0x7f01
jmp 0x7f01
movq %rax, %rbx
jmp 0x7fd4
movq %rax, %rbx
cmpq %r15, %r14
je 0x7fd4
leaq 0x160(%rsp), %r14
addq $-0x40, %r15
movq %r15, %rdi
callq 0x8626
cmpq %r14, %r15
jne 0x7f1d
jmp 0x7fd4
movq %rax, %rbx
jmp 0x7f65
movq %rax, %rbx
jmp 0x7f81
movq %rax, %rbx
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x7f65
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x42e0
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x7f81
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x42e0
xorl %r14d, %r14d
movq 0x118(%rsp,%r14), %rdi
leaq (%r15,%r14), %rax
cmpq %rdi, %rax
je 0x7fa0
movq (%rax), %rsi
incq %rsi
callq 0x42e0
addq $-0x28, %r14
cmpq $-0xa0, %r14
jne 0x7f84
jmp 0x7fb4
jmp 0x7fb1
movq %rax, %rbx
movl $0x100, %r14d           # imm = 0x100
leaq (%rsp,%r14), %rdi
addq $0x160, %rdi            # imm = 0x160
callq 0x8626
addq $-0x40, %r14
cmpq $-0x40, %r14
jne 0x7fba
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x7ff0
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42e0
movq %rbx, %rdi
callq 0x4590