// File: /workspace/github_cpp_makefile_star2_O1/tylerkaraszewski[P]Argyle/HttpRequest.cpp
// Function: HttpRequest::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
size_t HttpRequest::parse(const string& buffer)
{
  size_t headerEnd = buffer.find("\r\n\r\n");
  if (headerEnd == buffer.npos)
  {
    return 0;
  }

  // Ok, now we parse this.
  size_t startOffset = 0;
  size_t endOffset = 0;

  // Special handling for the first line.
  endOffset = buffer.find_first_of(SPACES);
  if (endOffset == buffer.npos)
  {
    m_httpError = 400;
    return headerEnd + 4;
  }
  m_method = buffer.substr(startOffset, endOffset);
  startOffset = buffer.find_first_not_of(SPACES, endOffset);
  if (startOffset == buffer.npos)
  {
    m_httpError = 400;
    return headerEnd + 4;
  }
  endOffset = buffer.find_first_of(SPACES, startOffset);
  if (endOffset == buffer.npos)
  {
    m_httpError = 400;
    return headerEnd + 4;
  }
  m_path = buffer.substr(startOffset, endOffset - startOffset);
  startOffset = buffer.find_first_not_of(SPACES, endOffset);
  if (startOffset == buffer.npos)
  {
    m_httpError = 400;
    return headerEnd + 4;
  }
  endOffset = buffer.find_first_of(NEWLINES, startOffset);
  if (endOffset == buffer.npos)
  {
    m_httpError = 400;
    return headerEnd + 4;
  }
  m_httpVersion = buffer.substr(startOffset, endOffset - startOffset);

  size_t pathOffset = m_path.find_first_of("#");
  if (pathOffset != m_path.npos)
  {
    m_path = m_path.substr(0, pathOffset);
  }
  pathOffset = m_path.find_first_of("?");
  if (pathOffset != m_path.npos)
  {
    m_queryString = m_path.substr(pathOffset);
    m_path = m_path.substr(0, pathOffset);
  }

  // Now we loop across all the headers we've got.
  startOffset = buffer.find_first_not_of(NEWLINES, endOffset);
  while (endOffset < headerEnd)
  {
    endOffset = buffer.find_first_of(SEPARATOR, startOffset);
    if (endOffset == buffer.npos)
    {
      break;
    }
    string headerName = buffer.substr(startOffset, endOffset - startOffset);
    headerName = headerName.substr(0, headerName.find_last_not_of(SPACES) + 1);
    startOffset = buffer.find_first_not_of(SPACES, endOffset + 1);
    if (startOffset == buffer.npos)
    {
      break;
    }
    endOffset = buffer.find_first_of(NEWLINES, startOffset);
    if (endOffset == buffer.npos)
    {
      break;
    }
    string value = buffer.substr(startOffset, endOffset - startOffset);
    startOffset = buffer.find_first_not_of(NEWLINES, endOffset);
    while ((buffer.find_first_of(SPACES) == startOffset) && (startOffset < headerEnd))
    {
      endOffset = buffer.find_first_of(NEWLINES, startOffset);
      if (endOffset == buffer.npos)
      {
        break;
      }
      value += buffer.substr(startOffset, endOffset - startOffset);
      startOffset = buffer.find_first_not_of(NEWLINES, endOffset);
      if (startOffset == buffer.npos)
      {
        break;
      }
    }

    toLower(headerName);
    if (headerName == "user-agent")
    {
      m_userAgent = value;
    }
    else if (headerName == "if-modified-since")
    {
      m_ifModifiedSince = Utils::parseHttpDate(value);
    }
    m_headers.insert(pair<string, string>(headerName, value));
  }

  // Set our keep-alive flag.
  HeaderMap::const_iterator it = m_headers.find("connection");
  {
    string c = it->second;
    toLower(c);
    if (c.find("keep-alive") != c.npos)
    {
      m_keepAlive = true;
    }
  }

  // Now we need to parse the request body.
  it = m_headers.find("content-length");
  if (it != m_headers.end())
  {
    const string& l = it->second;
    m_contentLength = strtoll(l.c_str(), NULL, 10);
  }

  // '4' is the \r\n\r\n following the headers.
  unsigned long long totalSize = headerEnd + 4 + m_contentLength;
  if (buffer.size() >= totalSize)
  {
    m_body = buffer.substr(headerEnd + 4, m_contentLength);
  }
  else
  {
    totalSize = 0;
  }

  return totalSize;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %r15
movq %rdi, %r14
leaq 0x5588(%rip), %rsi      # 0xc232
xorl %ebx, %ebx
movl $0x4, %ecx
movq %r15, %rdi
xorl %edx, %edx
callq 0x3500
cmpq $-0x1, %rax
je 0x744e
movq %rax, %rbp
movq 0x9639(%rip), %rsi      # 0x10308
movq 0x963a(%rip), %rcx      # 0x10310
movq %r15, %rdi
xorl %edx, %edx
callq 0x3420
cmpq $-0x1, %rax
je 0x743c
movq %rax, %rbx
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x32b0
leaq 0x10(%r14), %rdi
movq %r12, %rsi
callq 0x3360
movq (%r12), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x6d29
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x95d8(%rip), %rsi      # 0x10308
movq 0x95d9(%rip), %rcx      # 0x10310
movq %r15, %rdi
movq %rbx, %rdx
callq 0x34e0
cmpq $-0x1, %rax
je 0x743c
movq %rax, %rbx
movq 0x95b2(%rip), %rsi      # 0x10308
movq 0x95b3(%rip), %rcx      # 0x10310
movq %r15, %rdi
movq %rax, %rdx
callq 0x3420
cmpq $-0x1, %rax
je 0x743c
movq %rax, %r12
movq %rax, %rcx
subq %rbx, %rcx
leaq 0x8(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x32b0
movq %r14, %rbx
addq $0x30, %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x3360
movq (%r13), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x6dbb
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x9546(%rip), %rsi      # 0x10308
movq 0x9547(%rip), %rcx      # 0x10310
movq %r15, %rdi
movq %r12, %rdx
callq 0x34e0
cmpq $-0x1, %rax
je 0x7463
movq %rax, %r13
movq 0x9540(%rip), %rsi      # 0x10328
movq 0x9541(%rip), %rcx      # 0x10330
movq %r15, %rdi
movq %rax, %rdx
callq 0x3420
cmpq $-0x1, %rax
je 0x7463
movq %rax, %r12
movq %rbp, 0x50(%rsp)
movq %rax, %rcx
subq %r13, %rcx
leaq 0x8(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x32b0
movq %rbx, 0x48(%rsp)
leaq 0x50(%rbx), %rdi
movq %rbp, %rsi
callq 0x3360
movq (%rbp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x6e51
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x53df(%rip), %rsi      # 0xc237
movl $0x1, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x3420
cmpq $-0x1, %rax
movq 0x50(%rsp), %rbp
je 0x6ead
leaq 0x8(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x32b0
movq %r14, %rdi
movq %r13, %rsi
callq 0x3360
movq (%r13), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x6ead
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x5385(%rip), %rsi      # 0xc239
movl $0x1, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x3420
cmpq $-0x1, %rax
je 0x6f59
movq %rax, %r13
leaq 0x8(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
movq %rax, %rdx
movq $-0x1, %rcx
callq 0x32b0
movq 0x48(%rsp), %rax
leaq 0xc0(%rax), %rdi
movq %rbp, %rsi
callq 0x3360
movq (%rbp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x6f19
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x8(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0x32b0
movq %r14, %rdi
movq %rbp, %rsi
callq 0x3360
movq (%rbp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x6f54
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x50(%rsp), %rbp
movq 0x93c8(%rip), %rsi      # 0x10328
movq 0x93c9(%rip), %rcx      # 0x10330
movq %r15, %rdi
movq %r12, %rdx
callq 0x34e0
movq %rax, %rbx
movq 0x48(%rsp), %rcx
leaq 0xe8(%rcx), %rax
movq %rax, 0xa0(%rsp)
leaq 0x70(%rcx), %rax
movq %rax, 0x58(%rsp)
cmpq %rbp, %r12
jae 0x72f6
movq 0x93a6(%rip), %rsi      # 0x10348
movq 0x93a7(%rip), %rcx      # 0x10350
movq %r15, %rdi
movq %rbx, %rdx
callq 0x3420
cmpq $-0x1, %rax
je 0x72f6
movq %rax, %r12
movq %rax, %rcx
subq %rbx, %rcx
leaq 0x80(%rsp), %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %rdi, %rbx
callq 0x32b0
movq 0x9324(%rip), %rsi      # 0x10308
movq 0x9325(%rip), %rcx      # 0x10310
movq %rbx, %rdi
movq $-0x1, %rdx
callq 0x34a0
leaq 0x1(%rax), %rcx
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x32b0
leaq 0x18(%rsp), %r13
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3360
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x7037
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x1(%r12), %rdx
movq 0x92c5(%rip), %rsi      # 0x10308
movq 0x92c6(%rip), %rcx      # 0x10310
movq %r15, %rdi
callq 0x34e0
cmpq $-0x1, %rax
je 0x7190
movq %rax, %rbx
movq 0x92c2(%rip), %rsi      # 0x10328
movq 0x92c3(%rip), %rcx      # 0x10330
movq %r15, %rdi
movq %rax, %rdx
callq 0x3420
cmpq $-0x1, %rax
je 0x7199
movq %rax, %r12
movq %rax, %rcx
subq %rbx, %rcx
leaq 0x60(%rsp), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x32b0
movq 0x9286(%rip), %rsi      # 0x10328
movq 0x9287(%rip), %rcx      # 0x10330
movq %r15, %rdi
movq %r12, %rdx
callq 0x34e0
movq %rax, %rbx
movq 0x924a(%rip), %rsi      # 0x10308
movq 0x924b(%rip), %rcx      # 0x10310
movq %r15, %rdi
xorl %edx, %edx
callq 0x3420
cmpq %rbp, %rbx
leaq 0x8(%rsp), %r14
jae 0x71b8
cmpq %rbx, %rax
jne 0x71b8
movq 0x923b(%rip), %rsi      # 0x10328
movq 0x923c(%rip), %rcx      # 0x10330
movq %r15, %rdi
movq %rbx, %rdx
callq 0x3420
cmpq $-0x1, %rax
je 0x71a8
movq %rax, %r12
movq %rax, %rcx
subq %rbx, %rcx
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x32b0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x60(%rsp), %rdi
callq 0x30f0
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x714b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x91d6(%rip), %rsi      # 0x10328
movq 0x91d7(%rip), %rcx      # 0x10330
movq %r15, %rdi
movq %r12, %rdx
callq 0x34e0
cmpq $-0x1, %rax
je 0x71b1
movq %rax, %rbx
movq 0x9194(%rip), %rsi      # 0x10308
movq 0x9195(%rip), %rcx      # 0x10310
movq %r15, %rdi
xorl %edx, %edx
callq 0x3420
cmpq %rbp, %rbx
jb 0x70dd
jmp 0x71b8
movq $-0x1, %rbx
jmp 0x71a0
movq $-0x1, %r12
xorl %r13d, %r13d
jmp 0x72c8
movq $-0x1, %r12
jmp 0x71b8
movq $-0x1, %rbx
movq 0x88(%rsp), %r13
testq %r13, %r13
je 0x71e8
movq 0x80(%rsp), %rbp
xorl %r14d, %r14d
movsbl (%rbp,%r14), %edi
callq 0x33d0
movb %al, (%rbp,%r14)
incq %r14
cmpq %r14, %r13
jne 0x71d0
leaq 0x80(%rsp), %r14
movq %r14, %rdi
leaq 0x5041(%rip), %rsi      # 0xc23b
callq 0x30d0
testl %eax, %eax
je 0x7233
movq %r14, %rdi
leaq 0x4f60(%rip), %rsi      # 0xc16d
callq 0x30d0
testl %eax, %eax
leaq 0x18(%rsp), %r13
jne 0x724a
leaq 0x60(%rsp), %rdi
callq 0xad98
movq 0x48(%rsp), %rcx
movq %rax, 0x108(%rcx)
jmp 0x724a
movq 0xa0(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x3190
leaq 0x18(%rsp), %r13
leaq 0x8(%rsp), %r14
movq %r14, %rdi
leaq 0x80(%rsp), %rsi
leaq 0x60(%rsp), %rdx
callq 0x76a4
movq 0x58(%rsp), %rdi
movq %r14, %rsi
callq 0x77ce
movq 0x50(%rsp), %rbp
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x7292
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x72a9
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x72c5
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x3290
movb $0x1, %r13b
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x72ed
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x3290
testb %r13b, %r13b
jne 0x6f92
leaq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %r13
movq %r13, (%rdi)
leaq 0x4f3c(%rip), %rsi      # 0xc246
leaq 0x4f3f(%rip), %rdx      # 0xc250
callq 0x513e
leaq 0x8(%rsp), %rsi
movq 0x58(%rsp), %rdi
callq 0x798a
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x733f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x8(%rsp), %r12
movq %r13, (%r12)
movq 0x40(%rbx), %rsi
movq 0x48(%rbx), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x773e
movq 0x8(%r12), %rbx
testq %rbx, %rbx
je 0x7383
movq 0x8(%rsp), %r12
xorl %r13d, %r13d
movsbl (%r12,%r13), %edi
callq 0x33d0
movb %al, (%r12,%r13)
incq %r13
cmpq %r13, %rbx
jne 0x736d
leaq 0x4ec7(%rip), %rsi      # 0xc251
leaq 0x8(%rsp), %rdi
movl $0xa, %ecx
xorl %edx, %edx
callq 0x3500
cmpq $-0x1, %rax
movq 0x48(%rsp), %r14
je 0x73ab
movb $0x1, 0x8(%r14)
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %r13
cmpq %r13, %rdi
je 0x73c7
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x8(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x4e86(%rip), %rsi      # 0xc25c
leaq 0x4e8d(%rip), %rdx      # 0xc26a
callq 0x513e
leaq 0x8(%rsp), %rsi
movq 0x58(%rsp), %rdi
callq 0x798a
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x740b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x78(%r14), %rax
cmpq %rax, %rbx
je 0x7427
movq 0x40(%rbx), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x3080
movq %rax, (%r14)
movq (%r14), %rcx
leaq (%rcx,%rbp), %rbx
addq $0x4, %rbx
cmpq %rbx, 0x8(%r15)
jae 0x746f
xorl %ebx, %ebx
jmp 0x744e
movl $0x190, 0xe0(%r14) # imm = 0x190
addq $0x4, %rbp
movq %rbp, %rbx
movq %rbx, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x190, 0xe0(%rbx)      # imm = 0x190
jmp 0x7447
addq $0x4, %rbp
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x32b0
addq $0xa0, %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x3360
movq (%r12), %rdi
cmpq %r13, %rdi
je 0x744e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x744e
jmp 0x74b4
jmp 0x74cc
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x754b
movq 0x18(%rsp), %rsi
jmp 0x7543
movq %rax, %rbx
jmp 0x754b
jmp 0x74eb
jmp 0x74eb
jmp 0x74e6
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x7708
jmp 0x750a
movq %rax, %rbx
jmp 0x7526
movq %rax, %rbx
jmp 0x750a
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x750a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x7526
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x754b
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x3290
movq %rbx, %rdi
callq 0x3520
nop