// File: /workspace/github_c_makefile_star2_O1/deplinenoise[P]tundra/src/ScanCache.cpp
// Function: t2::ScanCacheInsert(t2::ScanCache*, t2::HashDigest const&, unsigned long, char const**, int)
void ScanCacheInsert(
    ScanCache*          self,
    const HashDigest&   key,
    uint64_t            timestamp,
    const char**        included_files,
    int                 count)
{
  AtomicIncrement(&g_Stats.m_ScanCacheInserts);

  ReadWriteLockWrite(&self->m_Lock);

  ScanCache::Record* record = LookupDynamic(self, key);

  // See if we have this record already (races to insert same include set are possible)
  if (nullptr == record || record->m_FileTimestamp != timestamp)
  {
    // Make sure we have room to insert.
    ScanCachePrepareInsert(self);

    uint32_t table_size = self->m_TableSize;
#if ENABLED(USE_SHA1_HASH)
    uint32_t hash       = key.m_Words.m_C;
#elif ENABLED(USE_FAST_HASH)
    uint32_t hash       = key.m_Words32[0];
#endif
    uint32_t index      = hash &(table_size - 1);

    // Allocate a new record if needed
    const bool is_fresh = record == nullptr;

    if (is_fresh)
    {
      record        = LinearAllocate<ScanCache::Record>(self->m_Allocator);
      record->m_Key = key;
    }

    record->m_FileTimestamp = timestamp;
    record->m_IncludeCount  = count;
    record->m_Includes      = LinearAllocateArray<FileAndHash>(self->m_Allocator, count);

    for (int i = 0; i < count; ++i)
    {
      record->m_Includes[i].m_Filename = StrDup(self->m_Allocator, included_files[i]);
      record->m_Includes[i].m_FilenameHash = Djb2HashPath(included_files[i]);
    }

    if (is_fresh)
    {
      record->m_Next       = self->m_Table[index];
      self->m_Table[index] = record;
      self->m_RecordCount++;
    }
  }

  ReadWriteUnlockWrite(&self->m_Lock);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r8d, %r12d
movq %rcx, %r15
movq %rdx, 0x8(%rsp)
movq %rsi, %r13
movq %rdi, %r14
leaq 0xd5c2(%rip), %rax      # 0x1d5a0
lock
incl 0xc(%rax)
leaq 0x8(%rdi), %rbx
movq %rbx, %rdi
callq 0x34f0
testl %eax, %eax
jne 0x1022e
movq %r14, %rdi
movq %r13, 0x40(%rsp)
movq %r13, %rsi
callq 0xff82
movq %rax, %r13
movq %rax, %rbp
testq %rax, %rax
je 0x10020
movq 0x8(%rsp), %rax
cmpq %rax, 0x10(%rbp)
je 0x10213
movl %r12d, 0x24(%rsp)
movq %rbx, 0x38(%rsp)
movl 0x54(%r14), %r12d
testq %r12, %r12
movq %r15, 0x28(%rsp)
je 0x1004f
movl 0x50(%r14), %eax
shll $0x8, %eax
xorl %edx, %edx
divl %r12d
cmpl $0xc0, %eax
jb 0x100fe
movq %rbp, 0x18(%rsp)
movq 0x40(%r14), %rbx
leal 0x1(%r12), %edi
callq 0x607e
cmpl $0x41, %eax
movl $0x40, %r15d
cmovael %eax, %r15d
movq 0x58(%r14), %rbp
leaq (,%r15,8), %rax
movq %rax, 0x30(%rsp)
movq %r15, %rsi
shlq $0x6, %rsi
movq %rbx, 0x10(%rsp)
movq %rbx, %rdi
callq 0xef62
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
movq 0x30(%rsp), %rdx
callq 0x31b0
testq %r12, %r12
je 0x100df
leal -0x1(%r15), %eax
xorl %ecx, %ecx
movq (%rbp,%rcx,8), %rdx
testq %rdx, %rdx
je 0x100d7
movq 0x28(%rdx), %rsi
movl (%rdx), %edi
andl %eax, %edi
movq (%rbx,%rdi,8), %r8
movq %r8, 0x28(%rdx)
movq %rdx, (%rbx,%rdi,8)
movq %rsi, %rdx
testq %rsi, %rsi
jne 0x100bb
incq %rcx
cmpq %r12, %rcx
jne 0x100b1
movl %r15d, 0x54(%r14)
movq %rbx, 0x58(%r14)
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0xef6a
movq 0x18(%rsp), %rbp
movq 0x28(%rsp), %r15
movl 0x54(%r14), %eax
decl %eax
movq 0x40(%rsp), %rbx
andl (%rbx), %eax
movl %eax, 0x10(%rsp)
movq %r13, 0x18(%rsp)
testq %r13, %r13
jne 0x10135
movq 0x48(%r14), %rdi
movl $0x30, %esi
movl $0x8, %edx
callq 0xf030
movq %rax, %rbp
movups (%rbx), %xmm0
movups %xmm0, (%rax)
movq 0x8(%rsp), %rax
movq %rax, 0x10(%rbp)
movl 0x24(%rsp), %r12d
movl %r12d, 0x18(%rbp)
movq 0x48(%r14), %rdi
movslq %r12d, %rbx
movq %rbx, %rsi
shlq $0x4, %rsi
movl $0x8, %edx
callq 0xf030
movq %rax, 0x20(%rbp)
testl %ebx, %ebx
jle 0x101ee
movq %r15, %r13
movl %r12d, %eax
shlq $0x3, %rax
movq %rax, 0x8(%rsp)
xorl %r15d, %r15d
movq 0x48(%r14), %rbx
movq (%r13,%r15), %r12
movq %r12, %rdi
callq 0x3150
movq %r14, %r13
movq %rbp, %r14
movq %rax, %rbp
leaq 0x1(%rax), %rsi
movl $0x1, %edx
movq %rbx, %rdi
callq 0xf030
movq %rax, %rbx
movq %rax, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x3290
movb $0x0, (%rbx,%rbp)
movq %r14, %rbp
movq %r13, %r14
movq 0x28(%rsp), %r13
movq 0x20(%rbp), %rax
movq %rbx, (%rax,%r15,2)
movq (%r13,%r15), %rdi
callq 0x5df8
movq 0x20(%rbp), %rcx
movl %eax, 0x8(%rcx,%r15,2)
addq $0x8, %r15
cmpq %r15, 0x8(%rsp)
jne 0x1017d
cmpq $0x0, 0x18(%rsp)
movq 0x38(%rsp), %rbx
jne 0x10213
movq 0x58(%r14), %rax
movl 0x10(%rsp), %ecx
movq (%rax,%rcx,8), %rdx
movq %rdx, 0x28(%rbp)
movq %rbp, (%rax,%rcx,8)
incl 0x50(%r14)
movq %rbx, %rdi
callq 0x3430
testl %eax, %eax
jne 0x10237
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6ec8(%rip), %rdi      # 0x170fd
jmp 0x1023e
leaq 0x6ede(%rip), %rdi      # 0x1711c
xorl %eax, %eax
callq 0x5c85