// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x50(%rdi), %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x786c
movq %r14, %r15
subq %rax, %r15
je 0x780e
movq %rax, %r13
cmpq $0x0, 0x20(%rbx)
je 0x7807
movq %rsp, -0x48(%rbp)
leaq 0xf(%r15), %rax
andq $-0x10, %rax
movq %rsp, %rdi
subq %rax, %rdi
movq %rdi, %rsp
movq 0x20(%rbx), %rcx
pushq $0x1
popq %rsi
movq %rdi, -0x40(%rbp)
movq %r15, %rdx
callq 0x3420
movq %rax, %r14
cmpq %r15, %rax
je 0x77ca
movq 0x20(%rbx), %rdi
callq 0x3460
testl %eax, %eax
jne 0x77ca
movq 0x20(%rbx), %rdi
callq 0x3550
movl %eax, %ecx
movq 0x70(%rbx), %rax
movq %rax, -0x38(%rbp)
movl %ecx, -0x2c(%rbp)
movslq %ecx, %rsi
leaq -0xc8(%rbp), %r15
movq %r15, %rdi
callq 0x8104
leaq 0x1cc3(%rip), %rsi      # 0x940f
leaq -0x68(%rbp), %rdi
movq %r15, %rdx
callq 0x42fb
leaq 0x18cf(%rip), %rdx      # 0x902e
leaq -0x88(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x42dc
movl -0x2c(%rbp), %edi
callq 0x3110
leaq -0xa8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
movq %rax, %rdx
callq 0x42dc
leaq -0xa8(%rbp), %rsi
movq -0x38(%rbp), %rdi
callq 0x80f6
leaq -0xa8(%rbp), %rdi
callq 0x35d8
leaq -0x88(%rbp), %rdi
callq 0x35d8
leaq -0x68(%rbp), %rdi
callq 0x35d8
leaq -0xc8(%rbp), %rdi
callq 0x35d8
addq %r14, 0x28(%rbx)
movq %r12, %rdi
movq -0x40(%rbp), %rsi
movq %r14, %rdx
callq 0x3070
testq %r14, %r14
je 0x77ec
movq 0x8(%rbx), %rax
cmpq %rax, 0x28(%rbx)
jne 0x77fe
movb $0x1, 0x11(%rbx)
movq 0x20(%rbx), %rdi
callq 0x32b0
andq $0x0, 0x20(%rbx)
addq %r13, %r14
movq -0x48(%rbp), %rsp
jmp 0x780e
movb $0x1, 0x11(%rbx)
movq %r13, %r14
addq %r14, 0x18(%rbx)
movq %r14, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x35d8
jmp 0x7838
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x35d8
jmp 0x7849
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x35d8
jmp 0x7857
movq %rax, %rbx
leaq -0xc8(%rbp), %rdi
callq 0x35d8
movq %rbx, %rdi
callq 0x3510
nop