// File: /workspace/github_c_makefile_star2_O3/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, %ebp
movq %rcx, (%rsp)
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
leaq 0xdcb0(%rip), %rax      # 0x1d5a0
lock
incl 0xc(%rax)
leaq 0x8(%rdi), %rbx
movq %rbx, %rdi
callq 0x34f0
testl %eax, %eax
jne 0xfb49
movq %r14, %rdi
movq %r12, 0x38(%rsp)
movq %r12, %rsi
callq 0xf895
movq %rax, %r13
movq %rax, %r12
testq %rax, %rax
je 0xf92e
cmpq %r15, 0x10(%r12)
je 0xfb2e
movq %r15, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movl 0x54(%r14), %ecx
testq %rcx, %rcx
je 0xf957
movl 0x50(%r14), %eax
shll $0x8, %eax
xorl %edx, %edx
divl %ecx
cmpl $0xc0, %eax
jb 0xfa18
movl %ebp, 0x8(%rsp)
movq %r12, 0x10(%rsp)
movq 0x40(%r14), %rbx
leal 0x1(%rcx), %edi
movq %rcx, %r15
callq 0x5f02
cmpl $0x41, %eax
movl $0x40, %r12d
cmovael %eax, %r12d
movq 0x58(%r14), %rbp
leaq (,%r12,8), %rax
movq %rax, 0x18(%rsp)
movq %r12, %rsi
shlq $0x6, %rsi
movq %rbx, 0x20(%rsp)
movq %rbx, %rdi
callq 0xe882
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
movq 0x18(%rsp), %rdx
callq 0x31b0
movq %r15, %r9
testl %r9d, %r9d
movq (%rsp), %r15
je 0xf9f4
leal -0x1(%r12), %eax
xorl %ecx, %ecx
movq (%rbp,%rcx,8), %rdx
testq %rdx, %rdx
je 0xf9ec
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 0xf9d0
incq %rcx
cmpq %r9, %rcx
jne 0xf9c6
movl %r12d, 0x54(%r14)
movq %rbx, 0x58(%r14)
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0xe88a
movl 0x54(%r14), %ecx
movq 0x10(%rsp), %r12
movl 0x8(%rsp), %ebp
jmp 0xfa1c
movq (%rsp), %r15
decl %ecx
movq 0x38(%rsp), %rbx
andl (%rbx), %ecx
movq %rcx, 0x8(%rsp)
movq %r13, 0x10(%rsp)
testq %r13, %r13
jne 0xfa50
movq 0x48(%r14), %rdi
movl $0x30, %esi
movl $0x8, %edx
callq 0xe950
movq %rax, %r12
movups (%rbx), %xmm0
movups %xmm0, (%rax)
movq 0x28(%rsp), %rax
movq %rax, 0x10(%r12)
movl %ebp, 0x18(%r12)
movq 0x48(%r14), %rdi
movslq %ebp, %rbx
movq %rbx, %rsi
shlq $0x4, %rsi
movl $0x8, %edx
callq 0xe950
movq %rax, 0x20(%r12)
testl %ebx, %ebx
jle 0xfb05
movq %r15, %r13
movl %ebp, %eax
shlq $0x3, %rax
movq %rax, (%rsp)
xorl %r15d, %r15d
movq %r14, 0x40(%rsp)
movq 0x48(%r14), %rbx
movq %r12, %r14
movq (%r13,%r15), %r12
movq %r12, %rdi
callq 0x3150
movq %rax, %rbp
leaq 0x1(%rax), %rsi
movl $0x1, %edx
movq %rbx, %rdi
callq 0xe950
movq %rax, %rbx
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %r12
movq 0x40(%rsp), %r14
movq %rbp, %rdx
callq 0x3290
movb $0x0, (%rbx,%rbp)
movq 0x20(%r12), %rax
movq %rbx, (%rax,%r15,2)
movq (%r13,%r15), %rdi
callq 0x5c7c
movq 0x20(%r12), %rcx
movl %eax, 0x8(%rcx,%r15,2)
addq $0x8, %r15
cmpq %r15, (%rsp)
jne 0xfa99
cmpq $0x0, 0x10(%rsp)
movq 0x30(%rsp), %rbx
movq 0x8(%rsp), %rcx
jne 0xfb2e
movq 0x58(%r14), %rax
movl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
movq %rdx, 0x28(%r12)
movq %r12, (%rax,%rcx,8)
incl 0x50(%r14)
movq %rbx, %rdi
callq 0x3430
testl %eax, %eax
jne 0xfb52
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x75ad(%rip), %rdi      # 0x170fd
jmp 0xfb59
leaq 0x75c3(%rip), %rdi      # 0x1711c
xorl %eax, %eax
callq 0x5b09