// File: tap3edit[P]tap3xml/Buffin.cpp
// Function: Buffin::Buffin(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
Buffin::Buffin(
    const string filename,  /* Filename to be buffered */
    int mode=0              /* 0=Read complete file, 1=Read bytes on request from file */
) :
    _buffin(NULL),
    _curbuf(NULL)
{
    /* 1. Declarations and definitions */
    _mode=mode;
    _pos=0;


    /* 2. Open file */

    _file_in.open(filename.c_str(), ios::binary | ios::in);

    if (!_file_in.good())
    {
        cerr << "Unable to open file: " << filename << endl;
        err_trace(__FILE__, __LINE__);
    }


    /* 3. Getting file size */

    _file_in.seekg(0, ios_base::end);
    _end=_file_in.tellg();
    _file_in.seekg(0, ios_base::beg);

    if (!_end)
    {
        cerr << "File: " << filename << " is empty" << endl;
        err_trace( __FILE__, __LINE__) ;
    }


    /* 4. Proceed according to mode */

    if (mode)
    {
        /* 4.1. File read on request */
        ;
    } else {

        /* 4.2. File read complete into _buffin */

        {
            /* 4.2.2. Reading the whole file in buffin */

            try
            {
                _buffin=new uchar [_end+2];
            }
            catch(const bad_alloc &ba)
            {
                cerr << "Out of memory: " << ba.what() << endl ;
                err_trace( __FILE__, __LINE__) ;
            }

            _file_in.read((char *)_buffin, _end);

            /* Note: yy_scan_buffer() from flex needs two */
            /*       null bytes at the end of the string  */

            _buffin[_end+0]='\0';
            _buffin[_end+1]='\0';


            /* 4.2.3. File is not needed anymore */

            // _file_in.close();
        }

    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rsi, -0xd0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
movq $0x0, (%rdi)
movq $0x0, 0x8(%rdi)
addq $0x18, %rdi
movq %rdi, -0xe8(%rbp)
movq %rdi, %rax
movq %rax, -0xe0(%rbp)
callq 0x4400
movq -0xd8(%rbp), %rax
movq -0xd0(%rbp), %rdi
movl -0x14(%rbp), %ecx
movl %ecx, 0x230(%rax)
movq $0x0, 0x220(%rax)
callq 0x4160
movq %rax, -0xc8(%rbp)
movl $0x4, %edi
movl $0x8, %esi
callq 0x17ed0
movl %eax, -0xbc(%rbp)
jmp 0x17416
movl -0xbc(%rbp), %edx
movq -0xc8(%rbp), %rsi
movq -0xe8(%rbp), %rdi
callq 0x41f0
jmp 0x17431
movq -0xd8(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x18(%rcx), %rcx
leaq 0x18(%rax,%rcx), %rdi
callq 0x4680
movb %al, -0xe9(%rbp)
jmp 0x17452
movb -0xe9(%rbp), %al
testb $0x1, %al
jne 0x17544
jmp 0x17462
movq 0x19b7f(%rip), %rdi     # 0x30fe8
leaq 0xe711(%rip), %rsi      # 0x25b81
callq 0x4340
movq %rax, -0xf8(%rbp)
jmp 0x1747e
movq -0xd0(%rbp), %rsi
movq -0xf8(%rbp), %rdi
callq 0x42e0
movq %rax, -0x100(%rbp)
jmp 0x1749a
movq -0x100(%rbp), %rdi
movq 0x19b00(%rip), %rsi     # 0x30fa8
callq 0x43b0
jmp 0x174af
leaq -0x49(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x46e0
movq -0x108(%rbp), %rdx
leaq 0xe6ca(%rip), %rsi      # 0x25b97
leaq -0x48(%rbp), %rdi
callq 0x7670
jmp 0x174d8
movl $0x4d, -0x50(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x151c0
jmp 0x174ee
leaq -0x48(%rbp), %rdi
callq 0x41e0
leaq -0x49(%rbp), %rdi
callq 0x43d0
jmp 0x17544
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x178a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x17536
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x41e0
leaq -0x49(%rbp), %rdi
callq 0x43d0
jmp 0x178a8
movq -0xd8(%rbp), %rdi
addq $0x18, %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x4550
jmp 0x1755f
movq -0xd8(%rbp), %rdi
addq $0x18, %rdi
callq 0x46b0
movq %rdx, -0x118(%rbp)
movq %rax, -0x110(%rbp)
jmp 0x1757f
movq -0x118(%rbp), %rax
movq -0x110(%rbp), %rcx
movq %rcx, -0x60(%rbp)
movq %rax, -0x58(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x17ef0
movq %rax, -0x120(%rbp)
jmp 0x175a7
movq -0xd8(%rbp), %rdi
movq -0x120(%rbp), %rax
movq %rax, 0x228(%rdi)
addq $0x18, %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x4550
jmp 0x175cb
movq -0xd8(%rbp), %rax
cmpq $0x0, 0x228(%rax)
jne 0x176dc
movq 0x19a01(%rip), %rdi     # 0x30fe8
leaq 0xe4ef(%rip), %rsi      # 0x25add
callq 0x4340
movq %rax, -0x128(%rbp)
jmp 0x175fc
movq -0xd0(%rbp), %rsi
movq -0x128(%rbp), %rdi
callq 0x42e0
movq %rax, -0x130(%rbp)
jmp 0x17618
movq -0x130(%rbp), %rdi
leaq 0xe57c(%rip), %rsi      # 0x25ba2
callq 0x4340
movq %rax, -0x138(%rbp)
jmp 0x17634
movq -0x138(%rbp), %rdi
movq 0x19966(%rip), %rsi     # 0x30fa8
callq 0x43b0
jmp 0x17649
leaq -0x81(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x46e0
movq -0x140(%rbp), %rdx
leaq 0xe52d(%rip), %rsi      # 0x25b97
leaq -0x80(%rbp), %rdi
callq 0x7670
jmp 0x17675
movl $0x5a, -0x88(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x151c0
jmp 0x17691
leaq -0x80(%rbp), %rdi
callq 0x41e0
leaq -0x81(%rbp), %rdi
callq 0x43d0
jmp 0x176dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x176cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x41e0
leaq -0x81(%rbp), %rdi
callq 0x43d0
jmp 0x178a8
cmpl $0x0, -0x14(%rbp)
je 0x176e7
jmp 0x1789f
movq -0xd8(%rbp), %rax
movq 0x228(%rax), %rdi
addq $0x2, %rdi
callq 0x4030
movq %rax, -0x148(%rbp)
jmp 0x17707
movq -0xd8(%rbp), %rax
movq -0x148(%rbp), %rcx
movq %rcx, (%rax)
jmp 0x17811
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x178a8
movq -0x20(%rbp), %rdi
callq 0x4150
movq %rax, -0x90(%rbp)
movq 0x19898(%rip), %rdi     # 0x30fe8
leaq 0xe455(%rip), %rsi      # 0x25bac
callq 0x4340
movq %rax, -0x150(%rbp)
jmp 0x17765
movq -0x90(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq -0x150(%rbp), %rdi
movq %rax, %rsi
callq 0x4340
movq %rax, -0x158(%rbp)
jmp 0x1778d
movq -0x158(%rbp), %rdi
movq 0x1980d(%rip), %rsi     # 0x30fa8
callq 0x43b0
jmp 0x177a2
leaq -0xb1(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x46e0
movq -0x160(%rbp), %rdx
leaq 0xe3d4(%rip), %rsi      # 0x25b97
leaq -0xb0(%rbp), %rdi
callq 0x7670
jmp 0x177d1
movl $0x72, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x151c0
jmp 0x177f0
leaq -0xb0(%rbp), %rdi
callq 0x41e0
leaq -0xb1(%rbp), %rdi
callq 0x43d0
callq 0x4650
jmp 0x1780f
jmp 0x17811
movq -0xd8(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movq (%rax), %rsi
movq 0x228(%rax), %rdx
callq 0x44b0
jmp 0x17830
movq -0xd8(%rbp), %rcx
movq (%rcx), %rax
movq 0x228(%rcx), %rdx
movb $0x0, (%rax,%rdx)
movq (%rcx), %rax
movq 0x228(%rcx), %rcx
movb $0x0, 0x1(%rax,%rcx)
jmp 0x1789f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x17896
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1788a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x41e0
leaq -0xb1(%rbp), %rdi
callq 0x43d0
callq 0x4650
jmp 0x1789d
jmp 0x178a8
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0xe0(%rbp), %rdi
callq 0x40d0
movq -0x20(%rbp), %rdi
callq 0x46d0
movq %rax, %rdi
callq 0x7de0
nopw %cs:(%rax,%rax)