// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]tundra/src/DagGenerator.cpp
// Function: t2::WriteScanner(t2::BinaryLocator*, t2::BinarySegment*, t2::BinarySegment*, t2::BinarySegment*, t2::JsonObjectValue const*, t2::HashTable<t2::CommonStringRecord, 0u>*, t2::MemAllocLinear*)
static bool WriteScanner(BinaryLocator* ptr_out, BinarySegment* seg, BinarySegment* array_seg, BinarySegment* str_seg, const JsonObjectValue* data, HashTable<CommonStringRecord, kFlagCaseSensitive>* shared_strings, MemAllocLinear* scratch)
{
  if (!data)
    return false;

  const char* kind = FindStringValue(data, "Kind");
  const JsonArrayValue* incpaths = FindArrayValue(data, "IncludePaths");

  if (!kind || !incpaths)
    return false;

  BinarySegmentAlign(seg, 4);
  *ptr_out = BinarySegmentPosition(seg);

  ScannerType::Enum type;
  if (0 == strcmp(kind, "cpp"))
    type = ScannerType::kCpp;
  else if (0 == strcmp(kind, "generic"))
    type = ScannerType::kGeneric;
  else
    return false;

  BinarySegmentWriteInt32(seg, type);
  BinarySegmentWriteInt32(seg, (int) incpaths->m_Count);
  BinarySegmentWritePointer(seg, BinarySegmentPosition(array_seg));
  HashState h;
  HashInit(&h);
  HashAddString(&h, kind);
  for (size_t i = 0, count = incpaths->m_Count; i < count; ++i)
  {
    const char* path = incpaths->m_Values[i]->GetString();
    if (!path)
      return false;
    HashAddPath(&h, path);
    WriteCommonStringPtr(array_seg, str_seg, path, shared_strings, scratch);
  }

  void* digest_space = BinarySegmentAlloc(seg, sizeof(HashDigest));

  if (ScannerType::kGeneric == type)
  {
    uint32_t flags = 0;

    if (GetBoolean(data, "RequireWhitespace"))
      flags |= GenericScannerData::kFlagRequireWhitespace;
    if (GetBoolean(data, "UseSeparators"))
      flags |= GenericScannerData::kFlagUseSeparators;
    if (GetBoolean(data, "BareMeansSystem"))
      flags |= GenericScannerData::kFlagBareMeansSystem;

    BinarySegmentWriteUint32(seg, flags);

    const JsonArrayValue* follow_kws = FindArrayValue(data, "Keywords");
    const JsonArrayValue* nofollow_kws = FindArrayValue(data, "KeywordsNoFollow");

    size_t kw_count =
      (follow_kws ? follow_kws->m_Count : 0) +
      (nofollow_kws ? nofollow_kws->m_Count : 0);

    BinarySegmentWriteInt32(seg, (int) kw_count);
    if (kw_count > 0)
    {
      BinarySegmentAlign(array_seg, 4);
      BinarySegmentWritePointer(seg, BinarySegmentPosition(array_seg));
      auto write_kws = [array_seg, str_seg](const JsonArrayValue* array, bool follow) -> bool
      {
        if (array)
        {
          for (size_t i = 0, count = array->m_Count; i < count; ++i)
          {
            const JsonStringValue* value = array->m_Values[i]->AsString();
            if (!value)
              return false;
            WriteStringPtr(array_seg, str_seg, value->m_String);
            BinarySegmentWriteInt16(array_seg, (int16_t) strlen(value->m_String));
            BinarySegmentWriteUint8(array_seg, follow ? 1 : 0);
            BinarySegmentWriteUint8(array_seg, 0);
          }
        }
        return true;
      };
      if (!write_kws(follow_kws, true))
        return false;
      if (!write_kws(nofollow_kws, false))
        return false;
    }
    else
    {
      BinarySegmentWriteNullPointer(seg);
    }
  }

  HashFinalize(&h, static_cast<HashDigest*>(digest_space));

  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xa107
movb $0x0, -0x1(%rbp)
jmp 0xa507
movq -0x30(%rbp), %rdi
leaq 0x1a3c7(%rip), %rsi     # 0x244d9
xorl %eax, %eax
movl %eax, %edx
callq 0x8460
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rdi
leaq 0x1a3b4(%rip), %rsi     # 0x244de
callq 0x84e0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0xa141
cmpq $0x0, -0x48(%rbp)
jne 0xa14a
movb $0x0, -0x1(%rbp)
jmp 0xa507
movq -0x18(%rbp), %rdi
movl $0x4, %esi
callq 0x20cc0
movq -0x18(%rbp), %rdi
callq 0x20e20
movl %eax, -0x58(%rbp)
movq %rdx, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq -0x58(%rbp), %rcx
movq %rcx, (%rax)
movq -0x50(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rdi
leaq 0x1b5b3(%rip), %rsi     # 0x25739
callq 0x3658
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0xa19c
movl $0x0, -0x5c(%rbp)
jmp 0xa1c8
movq -0x40(%rbp), %rdi
leaq 0x1a344(%rip), %rsi     # 0x244eb
callq 0x3658
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0xa1bd
movl $0x1, -0x5c(%rbp)
jmp 0xa1c6
movb $0x0, -0x1(%rbp)
jmp 0xa507
jmp 0xa1c8
movq -0x18(%rbp), %rdi
movl -0x5c(%rbp), %esi
callq 0xbb00
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %esi
callq 0xbb00
movq -0x18(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x20(%rbp), %rdi
callq 0x20e20
movq -0x178(%rbp), %rdi
movl %eax, -0x70(%rbp)
movq %rdx, -0x68(%rbp)
movl -0x70(%rbp), %esi
movq -0x68(%rbp), %rdx
callq 0x20db0
leaq -0x110(%rbp), %rdi
callq 0x16f20
movq -0x40(%rbp), %rsi
leaq -0x110(%rbp), %rdi
callq 0x6de0
movq $0x0, -0x118(%rbp)
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x120(%rbp)
movq -0x118(%rbp), %rax
cmpq -0x120(%rbp), %rax
jae 0xa2d3
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x118(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xbb30
movq %rax, -0x128(%rbp)
cmpq $0x0, -0x128(%rbp)
jne 0xa28d
movb $0x0, -0x1(%rbp)
jmp 0xa507
movq -0x128(%rbp), %rsi
leaq -0x110(%rbp), %rdi
callq 0x6ef0
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x128(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq 0x10(%rbp), %r8
callq 0x7f90
movq -0x118(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x118(%rbp)
jmp 0xa24b
movq -0x18(%rbp), %rdi
movl $0x10, %esi
callq 0x20d40
movq %rax, -0x130(%rbp)
movl $0x1, %eax
cmpl -0x5c(%rbp), %eax
jne 0xa4f0
movl $0x0, -0x134(%rbp)
movq -0x30(%rbp), %rdi
leaq 0x1a1e8(%rip), %rsi     # 0x244f3
callq 0xb3a0
testb $0x1, %al
jne 0xa316
jmp 0xa325
movl -0x134(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x134(%rbp)
movq -0x30(%rbp), %rdi
leaq 0x1a1d5(%rip), %rsi     # 0x24505
callq 0xb3a0
testb $0x1, %al
jne 0xa33b
jmp 0xa34a
movl -0x134(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x134(%rbp)
movq -0x30(%rbp), %rdi
leaq 0x1a1be(%rip), %rsi     # 0x24513
callq 0xb3a0
testb $0x1, %al
jne 0xa360
jmp 0xa36f
movl -0x134(%rbp), %eax
orl $0x4, %eax
movl %eax, -0x134(%rbp)
movq -0x18(%rbp), %rdi
movl -0x134(%rbp), %esi
callq 0xbaa0
movq -0x30(%rbp), %rdi
leaq 0x1a19a(%rip), %rsi     # 0x24523
callq 0x84e0
movq %rax, -0x140(%rbp)
movq -0x30(%rbp), %rdi
leaq 0x1a18c(%rip), %rsi     # 0x2452c
callq 0x84e0
movq %rax, -0x148(%rbp)
cmpq $0x0, -0x140(%rbp)
je 0xa3ca
movq -0x140(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x180(%rbp)
jmp 0xa3d5
xorl %eax, %eax
movq %rax, -0x180(%rbp)
jmp 0xa3d5
movq -0x180(%rbp), %rax
movq %rax, -0x188(%rbp)
cmpq $0x0, -0x148(%rbp)
je 0xa401
movq -0x148(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x190(%rbp)
jmp 0xa40c
xorl %eax, %eax
movq %rax, -0x190(%rbp)
jmp 0xa40c
movq -0x188(%rbp), %rax
movq -0x190(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x150(%rbp)
movq -0x18(%rbp), %rdi
movq -0x150(%rbp), %rax
movl %eax, %esi
callq 0xbb00
cmpq $0x0, -0x150(%rbp)
jbe 0xa4e5
movq -0x20(%rbp), %rdi
movl $0x4, %esi
callq 0x20cc0
movq -0x18(%rbp), %rax
movq %rax, -0x198(%rbp)
movq -0x20(%rbp), %rdi
callq 0x20e20
movq -0x198(%rbp), %rdi
movl %eax, -0x160(%rbp)
movq %rdx, -0x158(%rbp)
movl -0x160(%rbp), %esi
movq -0x158(%rbp), %rdx
callq 0x20db0
movq -0x20(%rbp), %rax
movq %rax, -0x170(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x140(%rbp), %rsi
leaq -0x170(%rbp), %rdi
movl $0x1, %edx
callq 0xb400
testb $0x1, %al
jne 0xa4c4
movb $0x0, -0x1(%rbp)
jmp 0xa507
movq -0x148(%rbp), %rsi
leaq -0x170(%rbp), %rdi
xorl %edx, %edx
callq 0xb400
testb $0x1, %al
jne 0xa4e3
movb $0x0, -0x1(%rbp)
jmp 0xa507
jmp 0xa4ee
movq -0x18(%rbp), %rdi
callq 0xbba0
jmp 0xa4f0
movq -0x130(%rbp), %rsi
leaq -0x110(%rbp), %rdi
callq 0x16f70
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
nopw %cs:(%rax,%rax)