// File: /workspace/github_cpp_makefile_star2_O3/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 0x9d1e
movq %r14, %r15
subq %rax, %r15
je 0x9c82
movq %rax, %r13
cmpq $0x0, 0x20(%rbx)
je 0x9ae9
movq %rsp, -0x88(%rbp)
leaq 0xf(%r15), %rax
andq $-0x10, %rax
movq %rsp, %rdi
subq %rax, %rdi
movq %rdi, %rsp
movq 0x20(%rbx), %rcx
movl $0x1, %esi
movq %rdi, -0x80(%rbp)
movq %r15, %rdx
callq 0x33f0
movq %rax, %r14
cmpq %r15, %rax
je 0x9c41
movq 0x20(%rbx), %rdi
callq 0x3450
testl %eax, %eax
jne 0x9c41
movq 0x20(%rbx), %rdi
callq 0x3550
movl %eax, %ecx
movq 0x70(%rbx), %rax
movq %rax, -0x78(%rbp)
movl %ecx, -0x2c(%rbp)
movslq %ecx, %rsi
leaq -0xc8(%rbp), %r15
movq %r15, %rdi
callq 0xabbc
leaq 0x2955(%rip), %rcx      # 0xc408
movl $0x17, %r8d
movq %r15, %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 0x9af5
movq %rdx, -0x50(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x40(%rbp)
jmp 0x9afb
movb $0x1, 0x11(%rbx)
movq %r13, %r14
jmp 0x9c82
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 0x2511(%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 0x9b46
movq %rdx, -0x70(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x60(%rbp)
jmp 0x9b4c
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
leaq -0x70(%rbp), %r15
movq %rdx, 0x8(%r15)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl -0x2c(%rbp), %edi
callq 0x3120
movq %r15, %rdi
movq %rax, %rsi
callq 0x3560
leaq -0x98(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x9ba7
movq %rdx, -0xa8(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x98(%rbp)
jmp 0x9bae
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq -0xa8(%rbp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x78(%rbp), %rdi
callq 0xabae
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
je 0x9bf0
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x9c09
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x9c22
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x3290
leaq -0xb8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9c41
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x3290
addq %r14, 0x28(%rbx)
movq %r12, %rdi
movq -0x80(%rbp), %rsi
movq %r14, %rdx
callq 0x3070
testq %r14, %r14
je 0x9c63
movq 0x8(%rbx), %rax
cmpq %rax, 0x28(%rbx)
jne 0x9c78
movb $0x1, 0x11(%rbx)
movq 0x20(%rbx), %rdi
callq 0x3270
movq $0x0, 0x20(%rbx)
addq %r13, %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 %r15, %rdi
je 0x9cbb
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x3290
jmp 0x9cbb
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x9cd9
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x3290
jmp 0x9cd9
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x9cf7
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x3290
jmp 0x9cf7
movq %rax, %rbx
leaq -0xb8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9d16
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x3290
movq %rbx, %rdi
callq 0x3520