// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movl %r8d, %ebp
movq %rcx, %r15
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %rbx
leaq 0xeed4(%rip), %rax      # 0x1d5a0
lock
incl 0xc(%rax)
leaq 0x8(%rdi), %r14
movq %r14, %rdi
callq 0xf0d1
movq %rbx, %rdi
movq %r12, 0x30(%rsp)
movq %r12, %rsi
callq 0xe664
movq %rax, %rcx
movq %rax, %r12
testq %rax, %rax
je 0xe702
cmpq %r13, 0x10(%r12)
je 0xe85e
movq %r13, 0x20(%rsp)
movq %r14, 0x28(%rsp)
movl 0x54(%rbx), %r13d
testq %r13, %r13
movq %rcx, 0x18(%rsp)
je 0xe730
movl 0x50(%rbx), %eax
shll $0x8, %eax
xorl %edx, %edx
divl %r13d
cmpl $0xc0, %eax
jb 0xe7b4
movl %ebp, 0xc(%rsp)
movq 0x40(%rbx), %rax
movq %rax, 0x10(%rsp)
leal 0x1(%r13), %edi
callq 0x5b0d
cmpl $0x41, %eax
pushq $0x40
popq %rbp
cmovael %eax, %ebp
movq 0x58(%rbx), %r14
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0xf143
leal -0x1(%rbp), %ecx
xorl %edx, %edx
cmpq %r13, %rdx
je 0xe793
movq (%r14,%rdx,8), %rsi
testq %rsi, %rsi
je 0xe78e
movq 0x28(%rsi), %rdi
movl (%rsi), %r8d
andl %ecx, %r8d
movq (%rax,%r8,8), %r9
movq %r9, 0x28(%rsi)
movq %rsi, (%rax,%r8,8)
movq %rdi, %rsi
jmp 0xe76e
incq %rdx
jmp 0xe765
movl %ebp, 0x54(%rbx)
movq %rax, 0x58(%rbx)
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0xd7a2
movl 0x54(%rbx), %r13d
movq 0x18(%rsp), %rcx
movl 0xc(%rsp), %ebp
decl %r13d
movq 0x30(%rsp), %r14
andl (%r14), %r13d
testq %rcx, %rcx
jne 0xe7d7
movq 0x48(%rbx), %rdi
callq 0xf0eb
movq %rax, %r12
movups (%r14), %xmm0
movups %xmm0, (%rax)
movq 0x20(%rsp), %rax
movq %rax, 0x10(%r12)
movl %ebp, 0x18(%r12)
movq 0x48(%rbx), %rdi
movslq %ebp, %r14
movq %r14, %rsi
callq 0xf091
movq %rax, 0x20(%r12)
xorl %ebp, %ebp
testl %r14d, %r14d
cmovlel %ebp, %r14d
shlq $0x3, %r14
cmpq %rbp, %r14
je 0xe83a
movq 0x48(%rbx), %rdi
movq (%r15,%rbp), %rsi
callq 0xc824
movq 0x20(%r12), %rcx
movq %rax, (%rcx,%rbp,2)
movq (%r15,%rbp), %rdi
callq 0x58de
movq 0x20(%r12), %rcx
movl %eax, 0x8(%rcx,%rbp,2)
addq $0x8, %rbp
jmp 0xe807
cmpq $0x0, 0x18(%rsp)
movq 0x28(%rsp), %r14
jne 0xe85e
movq 0x58(%rbx), %rax
movl %r13d, %ecx
movq (%rax,%rcx,8), %rdx
movq %rdx, 0x28(%r12)
movq %r12, (%rax,%rcx,8)
incl 0x50(%rbx)
movq %r14, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xf0f6