// File: jansucan[P]diff-dd/src/buffered_stream.cpp
// Function: BufferedStream::Reader::Reader(std::istream&, unsigned long, unsigned long)
Reader::Reader(std::istream &istream, size_t buffer_capacity,
               size_t buffer_count)
    : m_buffer_count(buffer_count), m_buffer_capacity(buffer_capacity),
      m_istream(istream), m_buffers(buffer_count),
      m_buffer_index(buffer_count - 1), m_buffer_offset(buffer_capacity),
      m_buffer_size(buffer_capacity)
{
    for (size_t i = 0; i < m_buffer_count; ++i) {
        try {
            m_buffers[i] = std::shared_ptr<char[]>(new char[m_buffer_capacity]);
        } catch (const std::bad_alloc &e) {
            throw Error("cannot allocate buffer for input stream data");
        }
    }

    refill_next_buffer();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq 0x11093(%rip), %rcx     # 0x14ad0
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rcx
movq %rcx, 0x18(%rax)
addq $0x20, %rax
movq %rax, -0x98(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x21(%rbp), %rdi
movq %rdi, -0x88(%rbp)
callq 0x46a0
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
callq 0x46c0
jmp 0x3a9a
leaq -0x21(%rbp), %rdi
callq 0x4730
movq -0xa0(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
movq %rcx, 0x38(%rax)
movq -0x18(%rbp), %rcx
movq %rcx, 0x40(%rax)
movq -0x18(%rbp), %rcx
movq %rcx, 0x48(%rax)
movq $0x0, -0x40(%rbp)
movq -0xa0(%rbp), %rcx
movq -0x40(%rbp), %rax
cmpq 0x8(%rcx), %rax
jae 0x3c4e
movq -0xa0(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x3030
movq %rax, -0xa8(%rbp)
jmp 0x3afc
movq -0xa8(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x4750
jmp 0x3b0e
movq -0xa0(%rbp), %rdi
addq $0x20, %rdi
movq -0x40(%rbp), %rsi
callq 0x4780
movq %rax, %rdi
leaq -0x50(%rbp), %rsi
callq 0x47a0
leaq -0x50(%rbp), %rdi
callq 0x47d0
jmp 0x3c3b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x21(%rbp), %rdi
callq 0x4730
jmp 0x3c7d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x3c71
movq -0x30(%rbp), %rdi
callq 0x3100
movq %rax, -0x58(%rbp)
movb $0x1, -0x7a(%rbp)
movl $0x10, %edi
callq 0x3180
movq %rax, -0xb8(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x34a0
movq -0xb0(%rbp), %rdx
leaq 0xa452(%rip), %rsi      # 0xe004
leaq -0x78(%rbp), %rdi
callq 0x47f0
jmp 0x3bbd
movq -0xb8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x48a0
jmp 0x3bcf
movq -0xb8(%rbp), %rdi
movb $0x0, -0x7a(%rbp)
leaq 0x10f17(%rip), %rsi     # 0x14af8
leaq 0xcf8(%rip), %rdx       # 0x48e0
callq 0x3480
jmp 0x3c8e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x3c15
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x3528
leaq -0x79(%rbp), %rdi
callq 0x32f0
testb $0x1, -0x7a(%rbp)
jne 0x3c26
jmp 0x3c32
movq -0xb8(%rbp), %rdi
callq 0x3200
callq 0x3460
jmp 0x3c39
jmp 0x3c71
jmp 0x3c3d
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x3ace
movq -0xa0(%rbp), %rdi
callq 0x3c90
jmp 0x3c5c
addq $0xc0, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movq -0x98(%rbp), %rdi
callq 0x4910
movq -0x30(%rbp), %rdi
callq 0x3490
movq %rax, %rdi
callq 0x4900
nop