// File: /workspace/github_cpp_makefile_star2_O1/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, %r12
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x50(%rdi), %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x9d92
movq %rax, %r14
subq %rax, %r12
je 0x9cf6
cmpq $0x0, 0x20(%rbx)
je 0x9b5a
movq %rsp, -0x88(%rbp)
leaq 0xf(%r12), %rax
andq $-0x10, %rax
movq %rsp, %r13
subq %rax, %r13
movq %r13, %rsp
movq 0x20(%rbx), %rcx
movl $0x1, %esi
movq %r13, %rdi
movq %r12, %rdx
callq 0x33f0
cmpq %r12, %rax
movq %rax, %r12
je 0x9cb6
movq 0x20(%rbx), %rdi
callq 0x3450
testl %eax, %eax
jne 0x9cb6
movq %r12, -0x78(%rbp)
movq 0x20(%rbx), %rdi
callq 0x3550
movl %eax, %ecx
movq 0x70(%rbx), %rax
movq %rax, -0x80(%rbp)
movl %ecx, -0x2c(%rbp)
movslq %ecx, %rsi
leaq -0xc8(%rbp), %r12
movq %r12, %rdi
callq 0xac34
leaq 0x28e4(%rip), %rcx      # 0xc408
movl $0x17, %r8d
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x32e0
leaq -0x40(%rbp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x9b63
movq %rdx, -0x50(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x40(%rbp)
jmp 0x9b69
movb $0x1, 0x11(%rbx)
jmp 0x9cf6
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
leaq -0x50(%rbp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x24a3(%rip), %rsi      # 0xc02e
callq 0x3560
leaq -0x60(%rbp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x9bb4
movq %rdx, -0x70(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x60(%rbp)
jmp 0x9bba
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
leaq -0x70(%rbp), %r12
movq %rdx, 0x8(%r12)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl -0x2c(%rbp), %edi
callq 0x3120
movq %r12, %rdi
movq %rax, %rsi
callq 0x3560
leaq -0x98(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x9c17
movq %rdx, -0xa8(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x98(%rbp)
jmp 0x9c1f
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
leaq -0xa8(%rbp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x80(%rbp), %rdi
callq 0xac26
movq -0xa8(%rbp), %rdi
cmpq %r12, %rdi
je 0x9c61
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
movq -0x78(%rbp), %r12
je 0x9c7e
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x9c97
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x3290
leaq -0xb8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9cb6
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x3290
addq %r12, 0x28(%rbx)
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x3070
testq %r12, %r12
je 0x9cd7
movq 0x8(%rbx), %rax
cmpq %rax, 0x28(%rbx)
jne 0x9cec
movb $0x1, 0x11(%rbx)
movq 0x20(%rbx), %rdi
callq 0x3270
movq $0x0, 0x20(%rbx)
addq %r12, %r14
movq -0x88(%rbp), %rsp
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
movq -0xa8(%rbp), %rdi
cmpq %r12, %rdi
je 0x9d2f
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x3290
jmp 0x9d2f
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x9d4d
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x3290
jmp 0x9d4d
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x9d6b
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x3290
jmp 0x9d6b
movq %rax, %rbx
leaq -0xb8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9d8a
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x3290
movq %rbx, %rdi
callq 0x3520