// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
leaq 0x1517d(%rip), %rdi     # 0x2f590
addq $0xc, %rdi
callq 0x74e0
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0x1b870
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x1a360
movq %rax, -0x30(%rbp)
xorl %eax, %eax
cmpq -0x30(%rbp), %rax
je 0x1a454
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
cmpq -0x18(%rbp), %rax
je 0x1a59e
movq -0x8(%rbp), %rdi
callq 0x1a5c0
movq -0x8(%rbp), %rax
movl 0x54(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
andl %ecx, %eax
movl %eax, -0x3c(%rbp)
cmpq $0x0, -0x30(%rbp)
sete %al
andb $0x1, %al
movb %al, -0x3d(%rbp)
testb $0x1, -0x3d(%rbp)
je 0x1a4b8
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x1b8b0
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x24(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movslq -0x24(%rbp), %rsi
callq 0x1b7c0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x20(%rax)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x1a55f
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x20(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x15f70
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x44(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x7470
movl %eax, %ecx
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x44(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x1a4f1
testb $0x1, -0x3d(%rbp)
je 0x1a59c
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x30(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl -0x3c(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movl 0x50(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x50(%rax)
jmp 0x1a59e
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0x1b8e0
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)