// File: 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
movq %rsp, %rbp
subq $0x420, %rsp            # imm = 0x420
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x350(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x4570
movq -0x350(%rbp), %rax
movq -0x10(%rbp), %rcx
movq %rcx, (%rax)
movq (%rax), %rdi
callq 0x18630
movq %rax, -0x348(%rbp)
jmp 0xa316
movq -0x350(%rbp), %rax
movq -0x348(%rbp), %rcx
movl %ecx, -0x38(%rbp)
movq (%rax), %rdi
movq $0x0, -0x58(%rbp)
leaq -0x58(%rbp), %rsi
callq 0x18650
jmp 0xa33d
movq -0x350(%rbp), %rax
movq (%rax), %rdi
movq %rdi, -0x360(%rbp)
callq 0x187c0
movq %rax, -0x358(%rbp)
jmp 0xa35c
movq -0x358(%rbp), %rax
cmpq $0x1f4, %rax            # imm = 0x1F4
jle 0xa379
movl $0x1f4, %eax            # imm = 0x1F4
movq %rax, -0x368(%rbp)
jmp 0xa3a1
movq -0x350(%rbp), %rax
movq (%rax), %rdi
callq 0x187c0
movq %rax, -0x370(%rbp)
jmp 0xa391
movq -0x370(%rbp), %rax
movq %rax, -0x368(%rbp)
jmp 0xa3a1
movq -0x360(%rbp), %rdi
movq -0x368(%rbp), %rsi
callq 0x187e0
jmp 0xa3b6
movq -0x350(%rbp), %rax
movq (%rax), %rsi
leaq -0x98(%rbp), %rdi
callq 0x189f0
jmp 0xa3ce
leaq -0x78(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x15700
jmp 0xa3e0
leaq -0x30(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movq %rsi, -0x378(%rbp)
callq 0x4490
movq -0x378(%rbp), %rdi
callq 0x41e0
leaq -0x98(%rbp), %rdi
callq 0x41e0
leaq -0x1e0(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
leaq 0x1c76d(%rip), %rsi     # 0x26b8e
leaq 0x1ad54(%rip), %rdx     # 0x2517c
callq 0xb2b0
jmp 0xa42f
leaq -0x1a0(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
leaq 0x1ae5e(%rip), %rsi     # 0x252a2
leaq 0x1ad60(%rip), %rdx     # 0x251ab
callq 0xb390
jmp 0xa452
leaq -0x160(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
leaq 0x1ae3e(%rip), %rsi     # 0x252a5
leaq 0x1ad3d(%rip), %rdx     # 0x251ab
callq 0xb390
jmp 0xa475
leaq -0x120(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
leaq 0x1ae1e(%rip), %rsi     # 0x252a8
leaq 0x1ad16(%rip), %rdx     # 0x251a7
callq 0xb470
jmp 0xa498
leaq -0xe0(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
leaq 0x1ae02(%rip), %rsi     # 0x252af
leaq 0x1ae02(%rip), %rdx     # 0x252b6
callq 0xb470
jmp 0xa4bb
movl $0x0, -0x3c(%rbp)
cmpl $0x5, -0x3c(%rbp)
jge 0xa60b
movslq -0x3c(%rbp), %rax
shlq $0x6, %rax
leaq -0x1e0(%rbp,%rax), %rdi
callq 0x4250
movq %rax, %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x208(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4390
jmp 0xa4fa
movslq -0x3c(%rbp), %rax
leaq -0x1e0(%rbp), %rsi
shlq $0x6, %rax
addq %rax, %rsi
leaq -0x208(%rbp), %rdi
callq 0xb580
movb %al, -0x379(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x41e0
movb -0x379(%rbp), %al
testb $0x1, %al
jne 0xa539
jmp 0xa5fb
movq -0x350(%rbp), %rdi
movslq -0x3c(%rbp), %rax
shlq $0x6, %rax
leaq -0x1c0(%rbp,%rax), %rsi
addq $0x18, %rdi
callq 0x4050
jmp 0xa55b
jmp 0xa5fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xab39
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x41e0
jmp 0xab39
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movq -0x1e8(%rbp), %rax
leaq -0x1e0(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x388(%rbp)
je 0xa5e5
movq -0x388(%rbp), %rdi
addq $-0x40, %rdi
movq %rdi, -0x390(%rbp)
callq 0xb550
movq -0x390(%rbp), %rax
leaq -0x1e0(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x388(%rbp)
jne 0xa5b4
jmp 0xab39
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xaaeb
jmp 0xa5fd
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xa4c2
movq -0x350(%rbp), %rax
leaq -0x2b0(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
addq $0x8, %rax
movq %rax, -0x2c0(%rbp)
leaq 0x1ac88(%rip), %rsi     # 0x252ba
leaq -0x2c0(%rbp), %rdx
callq 0xb610
jmp 0xa640
movq -0x350(%rbp), %rax
leaq -0x288(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
addq $0x10, %rax
movq %rax, -0x2c8(%rbp)
leaq 0x1ac5c(%rip), %rsi     # 0x252c3
leaq -0x2c8(%rbp), %rdx
callq 0xb610
jmp 0xa675
movq -0x350(%rbp), %rax
leaq -0x260(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
addq $0xc, %rax
movq %rax, -0x2d0(%rbp)
leaq 0x1ac30(%rip), %rsi     # 0x252cc
leaq -0x2d0(%rbp), %rdx
callq 0xb610
jmp 0xa6aa
movq -0x350(%rbp), %rax
leaq -0x238(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
addq $0x14, %rax
movq %rax, -0x2d8(%rbp)
leaq 0x1ac04(%rip), %rsi     # 0x252d5
leaq -0x2d8(%rbp), %rdx
callq 0xb610
jmp 0xa6df
movq -0x350(%rbp), %rdi
addq $0x18, %rdi
leaq 0x1abc5(%rip), %rsi     # 0x252b6
callq 0x7d30
movb %al, -0x391(%rbp)
jmp 0xa6fe
movb -0x391(%rbp), %al
testb $0x1, %al
jne 0xa70d
jmp 0xa7b4
movq -0x350(%rbp), %rdi
movl $0x1, 0x8(%rdi)
movl $0x1, 0x10(%rdi)
movl $0x3, 0xc(%rdi)
movl $0x1, 0x14(%rdi)
addq $0x18, %rdi
leaq 0x1aa6c(%rip), %rsi     # 0x251a7
callq 0x4560
jmp 0xa742
jmp 0xa9d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movq -0x2b8(%rbp), %rax
leaq -0x2b0(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x3a0(%rbp)
je 0xa79e
movq -0x3a0(%rbp), %rdi
addq $-0x28, %rdi
movq %rdi, -0x3a8(%rbp)
callq 0xb690
movq -0x3a8(%rbp), %rax
leaq -0x2b0(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x3a0(%rbp)
jne 0xa76d
jmp 0xaaeb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xaa9d
movl $0x0, -0x3c(%rbp)
cmpl $0x4, -0x3c(%rbp)
jge 0xa912
movslq -0x3c(%rbp), %rax
leaq -0x2b0(%rbp), %rsi
imulq $0x28, %rax, %rax
addq %rax, %rsi
leaq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
callq 0x47c0
movl %eax, -0x34(%rbp)
cmpl $-0x1, %eax
je 0xa8e6
movslq -0x34(%rbp), %rax
movq %rax, -0x3b0(%rbp)
movslq -0x3c(%rbp), %rax
leaq (%rax,%rax,4), %rax
leaq -0x2b0(%rbp,%rax,8), %rdi
callq 0x4250
movq -0x3b0(%rbp), %rdx
addq %rax, %rdx
leaq -0x338(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x2, %ecx
callq 0x4390
jmp 0xa831
leaq -0x318(%rbp), %rdi
leaq -0x338(%rbp), %rsi
callq 0x158b0
jmp 0xa846
leaq -0x2f8(%rbp), %rdi
leaq -0x318(%rbp), %rsi
callq 0x15320
jmp 0xa85b
leaq -0x2f8(%rbp), %rdi
callq 0x4160
movq %rax, %rdi
callq 0x4610
movl %eax, %ecx
movslq -0x3c(%rbp), %rdx
leaq -0x2b0(%rbp), %rax
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movq 0x20(%rax), %rax
movl %ecx, (%rax)
leaq -0x2f8(%rbp), %rdi
callq 0x41e0
leaq -0x318(%rbp), %rdi
callq 0x41e0
leaq -0x338(%rbp), %rdi
callq 0x41e0
jmp 0xa902
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xa8d5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x318(%rbp), %rdi
callq 0x41e0
leaq -0x338(%rbp), %rdi
callq 0x41e0
jmp 0xaa9d
movslq -0x3c(%rbp), %rcx
leaq -0x2b0(%rbp), %rax
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
jmp 0xa904
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xa7bb
movq -0x350(%rbp), %rdi
addq $0x18, %rdi
leaq 0x1a883(%rip), %rsi     # 0x251a7
callq 0x7d30
movb %al, -0x3b1(%rbp)
jmp 0xa931
movb -0x3b1(%rbp), %al
testb $0x1, %al
jne 0xa93d
jmp 0xa999
movq -0x350(%rbp), %rax
movl 0x8(%rax), %ecx
movl %ecx, -0x3c(%rbp)
movl 0xc(%rax), %ecx
movl %ecx, 0x8(%rax)
movl -0x3c(%rbp), %ecx
movl %ecx, 0xc(%rax)
movl 0x10(%rax), %ecx
movl %ecx, -0x3c(%rbp)
movl 0x14(%rax), %ecx
movl %ecx, 0x10(%rax)
movl -0x3c(%rbp), %ecx
movl %ecx, 0x14(%rax)
cmpl $0x0, 0xc(%rax)
jge 0xa97c
movq -0x350(%rbp), %rax
movl $0x3, 0xc(%rax)
movq -0x350(%rbp), %rax
cmpl $0x0, 0x14(%rax)
jge 0xa997
movq -0x350(%rbp), %rax
movl $0x1, 0x14(%rax)
jmp 0xa999
movq -0x350(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jl 0xa9b3
movq -0x350(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jge 0xa9ce
movq -0x350(%rbp), %rdi
addq $0x18, %rdi
leaq 0x1a7b7(%rip), %rsi     # 0x2517c
callq 0x4560
jmp 0xa9cc
jmp 0xa9ce
jmp 0xa9d0
movq -0x350(%rbp), %rax
movq (%rax), %rdi
movslq -0x38(%rbp), %rax
movq %rax, -0x340(%rbp)
leaq -0x340(%rbp), %rsi
callq 0x18650
jmp 0xa9f3
leaq -0x2b0(%rbp), %rax
movq %rax, -0x3c8(%rbp)
addq $0xa0, %rax
movq %rax, -0x3c0(%rbp)
movq -0x3c0(%rbp), %rdi
addq $-0x28, %rdi
movq %rdi, -0x3d0(%rbp)
callq 0xb690
movq -0x3c8(%rbp), %rcx
movq -0x3d0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x3c0(%rbp)
jne 0xaa0e
leaq -0x1e0(%rbp), %rax
movq %rax, -0x3e0(%rbp)
addq $0x140, %rax            # imm = 0x140
movq %rax, -0x3d8(%rbp)
movq -0x3d8(%rbp), %rdi
addq $-0x40, %rdi
movq %rdi, -0x3e8(%rbp)
callq 0xb550
movq -0x3e0(%rbp), %rcx
movq -0x3e8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x3d8(%rbp)
jne 0xaa5a
leaq -0x30(%rbp), %rdi
callq 0x41e0
addq $0x420, %rsp            # imm = 0x420
popq %rbp
retq
leaq -0x2b0(%rbp), %rax
movq %rax, -0x3f8(%rbp)
addq $0xa0, %rax
movq %rax, -0x3f0(%rbp)
movq -0x3f0(%rbp), %rdi
addq $-0x28, %rdi
movq %rdi, -0x400(%rbp)
callq 0xb690
movq -0x3f8(%rbp), %rcx
movq -0x400(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x3f0(%rbp)
jne 0xaab8
jmp 0xaaeb
leaq -0x1e0(%rbp), %rax
movq %rax, -0x410(%rbp)
addq $0x140, %rax            # imm = 0x140
movq %rax, -0x408(%rbp)
movq -0x408(%rbp), %rdi
addq $-0x40, %rdi
movq %rdi, -0x418(%rbp)
callq 0xb550
movq -0x410(%rbp), %rcx
movq -0x418(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x408(%rbp)
jne 0xab06
jmp 0xab39
leaq -0x30(%rbp), %rdi
callq 0x41e0
movq -0x48(%rbp), %rdi
callq 0x46d0
nopl (%rax,%rax)