// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]tundra/src/IncludeScanner.cpp
// Function: t2::ScanLineGeneric(t2::MemAllocLinear*, char const*, t2::GenericScannerData const&)
static IncludeData*
ScanLineGeneric(MemAllocLinear* allocator, const char *start_in, const GenericScannerData& config)
{
	const char *start = start_in;
	const char *str_start;

  const bool require_ws     = 0 != (config.m_Flags & GenericScannerData::kFlagRequireWhitespace);
  const bool use_separators = 0 != (config.m_Flags & GenericScannerData::kFlagUseSeparators);
  const bool bare_is_system = 0 != (config.m_Flags & GenericScannerData::kFlagBareMeansSystem);

	while (isspace(*start))
		++start;

	if (require_ws && start == start_in)
		return nullptr;

  const KeywordData* keyword = nullptr;

  for (const KeywordData& kwdata : config.m_Keywords)
  {
    if (0 == strncmp(kwdata.m_String, start, kwdata.m_StringLength))
    {
      keyword = &kwdata;
      break;
		}
	}

	if (!keyword)
		return nullptr;

	start += keyword->m_StringLength;
	
  // TDDO: Should make this optional
	if (!isspace(*start++))
		return nullptr;

	while (isspace(*start))
		++start;

  IncludeData* dest = LinearAllocate<IncludeData>(allocator);

	if (use_separators)
	{
    char closing_separator;

    switch (*start++)
    {
      case '<':
        closing_separator = '>';
        break;
      case '>': // A really crude way to match <file>path...</file> in QRC files.
        closing_separator = '<';
        break;
      case '"':
        closing_separator = '"';
        break;
      default:
        return nullptr;
    }

		str_start = start;
		for (;;)
		{
			char ch = *start++;
			if (ch == closing_separator)
				break;
			if (!ch)
				return 0;
		}

    // start is pointing to the character after the closing separator, so wind it back one
    start--;

    dest->m_IsSystemInclude = '>' == closing_separator;
	}
	else
	{
		str_start = start;

		// just grab the next token 
		while (*start && !isspace(*start))
			++start;

		if (str_start == start)
			return 0;

    dest->m_IsSystemInclude = bare_is_system;
	}

	dest->m_StringLen    = (unsigned short) (start - str_start);
	dest->m_String       = StrDupN(allocator, str_start, dest->m_StringLen);
	dest->m_ShouldFollow = keyword->m_ShouldFollow ? true : false;
	dest->m_Next         = nullptr;
	return dest;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %ecx
andl $0x1, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
setne %al
andb $0x1, %al
movb %al, -0x31(%rbp)
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %ecx
andl $0x2, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
setne %al
andb $0x1, %al
movb %al, -0x32(%rbp)
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %ecx
andl $0x4, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
setne %al
andb $0x1, %al
movb %al, -0x33(%rbp)
movq -0x28(%rbp), %rax
movsbl (%rax), %edi
callq 0x3070
cmpl $0x0, %eax
je 0x21ce0
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x21cc1
testb $0x1, -0x31(%rbp)
je 0x21cfd
movq -0x28(%rbp), %rax
cmpq -0x18(%rbp), %rax
jne 0x21cfd
movq $0x0, -0x8(%rbp)
jmp 0x21f81
movq $0x0, -0x40(%rbp)
movq -0x20(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x22030
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
callq 0x22050
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
je 0x21d7d
movq -0x50(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
callq 0x6e20
movq %rax, %rdi
movq -0x28(%rbp), %rsi
movq -0x60(%rbp), %rax
movswq 0x4(%rax), %rdx
callq 0x3180
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x21d6d
movq -0x60(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x21d7d
jmp 0x21d6f
movq -0x50(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x50(%rbp)
jmp 0x21d2b
cmpq $0x0, -0x40(%rbp)
jne 0x21d91
movq $0x0, -0x8(%rbp)
jmp 0x21f81
movq -0x40(%rbp), %rax
movswl 0x4(%rax), %ecx
movq -0x28(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x28(%rbp)
movsbl (%rax), %edi
callq 0x3070
cmpl $0x0, %eax
jne 0x21dd0
movq $0x0, -0x8(%rbp)
jmp 0x21f81
jmp 0x21dd2
movq -0x28(%rbp), %rax
movsbl (%rax), %edi
callq 0x3070
cmpl $0x0, %eax
je 0x21df1
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x21dd2
movq -0x10(%rbp), %rdi
callq 0x22000
movq %rax, -0x68(%rbp)
testb $0x1, -0x32(%rbp)
je 0x21ebb
movq -0x28(%rbp), %rax
movq %rax, %rcx
incq %rcx
movq %rcx, -0x28(%rbp)
movsbl (%rax), %eax
movl %eax, -0x70(%rbp)
subl $0x22, %eax
je 0x21e43
jmp 0x21e23
movl -0x70(%rbp), %eax
subl $0x3c, %eax
je 0x21e37
jmp 0x21e2d
movl -0x70(%rbp), %eax
subl $0x3e, %eax
je 0x21e3d
jmp 0x21e49
movb $0x3e, -0x69(%rbp)
jmp 0x21e56
movb $0x3c, -0x69(%rbp)
jmp 0x21e56
movb $0x22, -0x69(%rbp)
jmp 0x21e56
movq $0x0, -0x8(%rbp)
jmp 0x21f81
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x28(%rbp)
movb (%rax), %al
movb %al, -0x6a(%rbp)
movsbl -0x6a(%rbp), %eax
movsbl -0x69(%rbp), %ecx
cmpl %ecx, %eax
jne 0x21e80
jmp 0x21e95
cmpb $0x0, -0x6a(%rbp)
jne 0x21e93
movq $0x0, -0x8(%rbp)
jmp 0x21f81
jmp 0x21e5e
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
movsbl -0x69(%rbp), %ecx
movl $0x3e, %eax
cmpl %ecx, %eax
sete %cl
movq -0x68(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x10(%rax)
jmp 0x21f20
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rcx
xorl %eax, %eax
cmpb $0x0, (%rcx)
movb %al, -0x71(%rbp)
je 0x21ee8
movq -0x28(%rbp), %rax
movsbl (%rax), %edi
callq 0x3070
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x21ef1
jmp 0x21eff
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x21ec3
movq -0x30(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0x21f13
movq $0x0, -0x8(%rbp)
jmp 0x21f81
movb -0x33(%rbp), %cl
movq -0x68(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x10(%rax)
movl -0x28(%rbp), %eax
movl -0x30(%rbp), %ecx
subl %ecx, %eax
movzwl %ax, %eax
movl %eax, %ecx
movq -0x68(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x15fb0
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
movb 0x6(%rax), %cl
xorl %eax, %eax
negb %cl
sbbl %eax, %eax
movb %al, %cl
movq -0x68(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x11(%rax)
movq -0x68(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x68(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nop