// File: tap3edit[P]tap3xml/NrtInfo.cpp
// Function: NrtInfo::buffin(Buffin*)
void NrtInfo::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",      "NRT"),    /* Nrt file */
    };

    for(i=0;i<2;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 *>("5f2901",  &_version),
        pair<string,int *>("5f2501",  &_release)
    };

    for(i=0;i<2;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 (_version<0 || _release<0)
        _type="ERR";


    _bfin->set_pos(bfin_pos);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2f0, %rsp            # imm = 0x2F0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x230(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x4570
movq -0x230(%rbp), %rax
movq -0x10(%rbp), %rcx
movq %rcx, (%rax)
movq (%rax), %rdi
callq 0x178d0
movq %rax, -0x228(%rbp)
jmp 0x9df6
movq -0x230(%rbp), %rax
movq -0x228(%rbp), %rcx
movl %ecx, -0x38(%rbp)
movq (%rax), %rdi
movq $0x0, -0x58(%rbp)
leaq -0x58(%rbp), %rsi
callq 0x178f0
jmp 0x9e1d
movq -0x230(%rbp), %rax
movq (%rax), %rdi
movq %rdi, -0x240(%rbp)
callq 0x17a60
movq %rax, -0x238(%rbp)
jmp 0x9e3c
movq -0x238(%rbp), %rax
cmpq $0x1f4, %rax            # imm = 0x1F4
jle 0x9e59
movl $0x1f4, %eax            # imm = 0x1F4
movq %rax, -0x248(%rbp)
jmp 0x9e81
movq -0x230(%rbp), %rax
movq (%rax), %rdi
callq 0x17a60
movq %rax, -0x250(%rbp)
jmp 0x9e71
movq -0x250(%rbp), %rax
movq %rax, -0x248(%rbp)
jmp 0x9e81
movq -0x240(%rbp), %rdi
movq -0x248(%rbp), %rsi
callq 0x17a80
jmp 0x9e96
movq -0x230(%rbp), %rax
movq (%rax), %rsi
leaq -0x98(%rbp), %rdi
callq 0x17c90
jmp 0x9eae
leaq -0x78(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x149a0
jmp 0x9ec0
leaq -0x30(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movq %rsi, -0x258(%rbp)
callq 0x4490
movq -0x258(%rbp), %rdi
callq 0x41e0
leaq -0x98(%rbp), %rdi
callq 0x41e0
leaq -0x120(%rbp), %rdi
movq %rdi, -0x128(%rbp)
leaq 0x1bbed(%rip), %rsi     # 0x25aee
leaq 0x1a273(%rip), %rdx     # 0x2417b
callq 0xa9d0
jmp 0x9f0f
leaq -0xe0(%rbp), %rdi
movq %rdi, -0x128(%rbp)
leaq 0x1a369(%rip), %rsi     # 0x2428d
leaq 0x1a365(%rip), %rdx     # 0x24290
callq 0xaab0
jmp 0x9f32
movl $0x0, -0x3c(%rbp)
cmpl $0x2, -0x3c(%rbp)
jge 0xa082
movslq -0x3c(%rbp), %rax
shlq $0x6, %rax
leaq -0x120(%rbp,%rax), %rdi
callq 0x4250
movq %rax, %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x148(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4390
jmp 0x9f71
movslq -0x3c(%rbp), %rax
leaq -0x120(%rbp), %rsi
shlq $0x6, %rax
addq %rax, %rsi
leaq -0x148(%rbp), %rdi
callq 0xabc0
movb %al, -0x259(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x41e0
movb -0x259(%rbp), %al
testb $0x1, %al
jne 0x9fb0
jmp 0xa072
movq -0x230(%rbp), %rdi
movslq -0x3c(%rbp), %rax
shlq $0x6, %rax
leaq -0x100(%rbp,%rax), %rsi
addq $0x10, %rdi
callq 0x4050
jmp 0x9fd2
jmp 0xa072
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xa454
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x41e0
jmp 0xa454
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movq -0x128(%rbp), %rax
leaq -0x120(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x268(%rbp)
je 0xa05c
movq -0x268(%rbp), %rdi
addq $-0x40, %rdi
movq %rdi, -0x270(%rbp)
callq 0xab90
movq -0x270(%rbp), %rax
leaq -0x120(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x268(%rbp)
jne 0xa02b
jmp 0xa454
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xa406
jmp 0xa074
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x9f39
movq -0x230(%rbp), %rax
leaq -0x1a0(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
addq $0x8, %rax
movq %rax, -0x1b0(%rbp)
leaq 0x1a1eb(%rip), %rsi     # 0x24294
leaq -0x1b0(%rbp), %rdx
callq 0xac50
jmp 0xa0b7
movq -0x230(%rbp), %rax
leaq -0x178(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
addq $0xc, %rax
movq %rax, -0x1b8(%rbp)
leaq 0x1a1bd(%rip), %rsi     # 0x2429b
leaq -0x1b8(%rbp), %rdx
callq 0xac50
jmp 0xa0ec
movl $0x0, -0x3c(%rbp)
cmpl $0x2, -0x3c(%rbp)
jge 0xa2ba
movslq -0x3c(%rbp), %rax
leaq -0x1a0(%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 0xa28e
movslq -0x34(%rbp), %rax
movq %rax, -0x278(%rbp)
movslq -0x3c(%rbp), %rax
leaq (%rax,%rax,4), %rax
leaq -0x1a0(%rbp,%rax,8), %rdi
callq 0x4250
movq -0x278(%rbp), %rdx
addq %rax, %rdx
leaq -0x218(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x2, %ecx
callq 0x4390
jmp 0xa169
leaq -0x1f8(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x14b50
jmp 0xa17e
leaq -0x1d8(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0x145c0
jmp 0xa193
leaq -0x1d8(%rbp), %rdi
callq 0x4160
movq %rax, %rdi
callq 0x4610
movl %eax, %ecx
movslq -0x3c(%rbp), %rdx
leaq -0x1a0(%rbp), %rax
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movq 0x20(%rax), %rax
movl %ecx, (%rax)
leaq -0x1d8(%rbp), %rdi
callq 0x41e0
leaq -0x1f8(%rbp), %rdi
callq 0x41e0
leaq -0x218(%rbp), %rdi
callq 0x41e0
jmp 0xa2aa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movq -0x1a8(%rbp), %rax
leaq -0x1a0(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x280(%rbp)
je 0xa241
movq -0x280(%rbp), %rdi
addq $-0x28, %rdi
movq %rdi, -0x288(%rbp)
callq 0xacd0
movq -0x288(%rbp), %rax
leaq -0x1a0(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x280(%rbp)
jne 0xa210
jmp 0xa406
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xa3ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xa27d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x41e0
leaq -0x218(%rbp), %rdi
callq 0x41e0
jmp 0xa3ba
movslq -0x3c(%rbp), %rcx
leaq -0x1a0(%rbp), %rax
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
jmp 0xa2ac
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xa0f3
movq -0x230(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jl 0xa2d4
movq -0x230(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jge 0xa2ef
movq -0x230(%rbp), %rdi
addq $0x10, %rdi
leaq 0x19e95(%rip), %rsi     # 0x2417b
callq 0x4560
jmp 0xa2ed
jmp 0xa2ef
movq -0x230(%rbp), %rax
movq (%rax), %rdi
movslq -0x38(%rbp), %rax
movq %rax, -0x220(%rbp)
leaq -0x220(%rbp), %rsi
callq 0x178f0
jmp 0xa312
leaq -0x1a0(%rbp), %rax
movq %rax, -0x298(%rbp)
addq $0x50, %rax
movq %rax, -0x290(%rbp)
movq -0x290(%rbp), %rdi
addq $-0x28, %rdi
movq %rdi, -0x2a0(%rbp)
callq 0xacd0
movq -0x298(%rbp), %rcx
movq -0x2a0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x290(%rbp)
jne 0xa32b
leaq -0x120(%rbp), %rax
movq %rax, -0x2b0(%rbp)
addq $0x80, %rax
movq %rax, -0x2a8(%rbp)
movq -0x2a8(%rbp), %rdi
addq $-0x40, %rdi
movq %rdi, -0x2b8(%rbp)
callq 0xab90
movq -0x2b0(%rbp), %rcx
movq -0x2b8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x2a8(%rbp)
jne 0xa377
leaq -0x30(%rbp), %rdi
callq 0x41e0
addq $0x2f0, %rsp            # imm = 0x2F0
popq %rbp
retq
leaq -0x1a0(%rbp), %rax
movq %rax, -0x2c8(%rbp)
addq $0x50, %rax
movq %rax, -0x2c0(%rbp)
movq -0x2c0(%rbp), %rdi
addq $-0x28, %rdi
movq %rdi, -0x2d0(%rbp)
callq 0xacd0
movq -0x2c8(%rbp), %rcx
movq -0x2d0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x2c0(%rbp)
jne 0xa3d3
jmp 0xa406
leaq -0x120(%rbp), %rax
movq %rax, -0x2e0(%rbp)
addq $0x80, %rax
movq %rax, -0x2d8(%rbp)
movq -0x2d8(%rbp), %rdi
addq $-0x40, %rdi
movq %rdi, -0x2e8(%rbp)
callq 0xab90
movq -0x2e0(%rbp), %rcx
movq -0x2e8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x2d8(%rbp)
jne 0xa421
jmp 0xa454
leaq -0x30(%rbp), %rdi
callq 0x41e0
movq -0x48(%rbp), %rdi
callq 0x46d0
nopw %cs:(%rax,%rax)