// File: tylerkaraszewski[P]Argyle/FileReader.cpp
// Function: FileReader::read(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, unsigned long)
size_t FileReader::read(string& buffer, const size_t maxBytesToRead)
{
  size_t bytesRead = 0;
  bytesRead += readFromInternalBufferString(m_headerBuffer, buffer, maxBytesToRead);
  if (bytesRead == maxBytesToRead)
  {
    m_bytesRead += bytesRead;
    return bytesRead;
  }

  if (m_file != NULL)
  {
    size_t remainingBytes = maxBytesToRead - bytesRead;
    char buf[remainingBytes];
    size_t fileBytes = fread(buf, 1, remainingBytes, m_file);
    if (fileBytes != remainingBytes)
    {
      // either EOF or error.
      if (!feof(m_file))
      {
        int err = ferror(m_file);
        m_logger.logError("FileReader fread error(" + Utils::llToString(err) + "): " + strerror(err));
      }
    }
    m_fileBytesRead += fileBytes;
    bytesRead += fileBytes;
    buffer.append(buf, fileBytes);

    if ((m_fileBytesRead == m_contentLength) || (fileBytes == 0))
    {
      m_done = true;
      fclose(m_file);
      m_file = NULL;
    }
  }
  else
  {
    m_done = true;
  }
  m_bytesRead += bytesRead;
  return bytesRead;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
movq $0x0, -0x28(%rbp)
movq %rdi, %rsi
addq $0x50, %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0xf4b0
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
jne 0xf210
movq -0xe8(%rbp), %rax
movq -0x28(%rbp), %rcx
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xf495
movq -0xe8(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0xf46f
movq -0xe8(%rbp), %rax
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rdx
subq %rdx, %rcx
movq %rcx, -0x30(%rbp)
movq -0x30(%rbp), %rcx
movq %rsp, %rdx
movq %rdx, -0x38(%rbp)
movq %rcx, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rdi
subq %rdx, %rdi
movq %rdi, -0xf0(%rbp)
movq %rdi, %rsp
movq %rcx, -0x40(%rbp)
movq -0x30(%rbp), %rdx
movq 0x20(%rax), %rcx
movl $0x1, %esi
callq 0x45a0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x30(%rbp), %rax
je 0xf3f8
movq -0xe8(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x45e0
cmpl $0x0, %eax
jne 0xf3f6
movq -0xe8(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x4700
movl %eax, %ecx
movq -0xe8(%rbp), %rax
movl %ecx, -0x4c(%rbp)
movq 0x70(%rax), %rax
movq %rax, -0x100(%rbp)
movslq -0x4c(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x10f70
movq -0xf8(%rbp), %rdx
leaq 0x4104(%rip), %rsi      # 0x133ef
leaq -0xb0(%rbp), %rdi
callq 0x6230
jmp 0xf2f9
leaq 0x3d12(%rip), %rdx      # 0x13012
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x61e0
jmp 0xf315
movl -0x4c(%rbp), %edi
callq 0x4150
movq %rax, %rdx
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x61e0
jmp 0xf332
movq -0x100(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x10f40
jmp 0xf344
leaq -0x70(%rbp), %rdi
callq 0x4788
leaq -0x90(%rbp), %rdi
callq 0x4788
leaq -0xb0(%rbp), %rdi
callq 0x4788
leaq -0xd0(%rbp), %rdi
callq 0x4788
jmp 0xf3f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
jmp 0xf3e5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
jmp 0xf3d9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
jmp 0xf3cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x4788
leaq -0x90(%rbp), %rdi
callq 0x4788
leaq -0xb0(%rbp), %rdi
callq 0x4788
leaq -0xd0(%rbp), %rdi
callq 0x4788
jmp 0xf49e
jmp 0xf3f8
movq -0xe8(%rbp), %rax
movq -0xf0(%rbp), %rsi
movq -0x48(%rbp), %rcx
addq 0x28(%rax), %rcx
movq %rcx, 0x28(%rax)
movq -0x48(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rdx
callq 0x40a0
movq -0xe8(%rbp), %rcx
movq 0x28(%rcx), %rax
cmpq 0x8(%rcx), %rax
je 0xf443
cmpq $0x0, -0x48(%rbp)
jne 0xf466
movq -0xe8(%rbp), %rax
movb $0x1, 0x11(%rax)
movq 0x20(%rax), %rdi
callq 0x43a0
movq -0xe8(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x38(%rbp), %rax
movq %rax, %rsp
jmp 0xf47a
movq -0xe8(%rbp), %rax
movb $0x1, 0x11(%rax)
movq -0xe8(%rbp), %rax
movq -0x28(%rbp), %rcx
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rbp, %rsp
popq %rbp
retq
movq -0xd8(%rbp), %rdi
callq 0x46b0
nopw (%rax,%rax)