// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]tundra/src/FileSign.cpp
// Function: t2::ComputeFileSignatureSha1(t2::HashState*, t2::StatCache*, t2::DigestCache*, char const*, unsigned int)
static void ComputeFileSignatureSha1(HashState* state, StatCache* stat_cache, DigestCache* digest_cache, const char* filename, uint32_t fn_hash)
{
  FileInfo file_info = StatCacheStat(stat_cache, filename, fn_hash);

  if (!file_info.Exists())
  {
    HashAddInteger(state, ~0ull);
    return;
  }

  HashDigest digest;

  if (!DigestCacheGet(digest_cache, filename, fn_hash, file_info.m_Timestamp, &digest))
  {
    TimingScope timing_scope(&g_Stats.m_FileDigestCount, &g_Stats.m_FileDigestTimeCycles);

    FILE* f = fopen(filename, "rb");
    if (!f)
    {
      HashAddString(state, "<missing>");
      return;
    }

    HashState h;
    HashInit(&h);

    char buffer[8192];
    while (size_t nbytes = fread(buffer, 1, sizeof buffer, f))
    {
      HashUpdate(&h, buffer, nbytes);
    }
    fclose(f);

    HashFinalize(&h, &digest);
    DigestCacheSet(digest_cache, filename, fn_hash, file_info.m_Timestamp, digest);
  }
  else
  {
    AtomicIncrement(&g_Stats.m_DigestCacheHits);
  }

  HashUpdate(state, &digest, sizeof(digest));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2140, %rsp           # imm = 0x2140
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl -0x24(%rbp), %ecx
leaq -0x40(%rbp), %rdi
callq 0x1dd10
leaq -0x40(%rbp), %rdi
callq 0x71b0
testb $0x1, %al
jne 0x20185
movq -0x8(%rbp), %rdi
movq $-0x1, %rsi
callq 0x170b0
jmp 0x2030b
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
movq -0x30(%rbp), %rcx
leaq -0x50(%rbp), %r8
callq 0x1f8c0
testb $0x1, %al
jne 0x202e6
leaq 0xf3e4(%rip), %rdx      # 0x2f590
movq %rdx, %rsi
addq $0xb4, %rsi
addq $0xb8, %rdx
leaq -0x68(%rbp), %rdi
callq 0x7220
movq -0x20(%rbp), %rdi
leaq 0x3db8(%rip), %rsi      # 0x23f89
callq 0x33c0
movq %rax, -0x2130(%rbp)
jmp 0x201df
movq -0x2130(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x20229
movq -0x8(%rbp), %rdi
leaq 0x54ca(%rip), %rsi      # 0x256c6
callq 0x6de0
jmp 0x20203
movl $0x1, -0x80(%rbp)
jmp 0x202d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x7270
jmp 0x20314
leaq -0x120(%rbp), %rdi
callq 0x16f20
jmp 0x20237
jmp 0x20239
movq -0x70(%rbp), %rcx
leaq -0x2120(%rbp), %rdi
movl $0x1, %esi
movl $0x2000, %edx           # imm = 0x2000
callq 0x34d0
movq %rax, -0x2138(%rbp)
jmp 0x2025c
movq -0x2138(%rbp), %rax
movq %rax, -0x2128(%rbp)
cmpq $0x0, -0x2128(%rbp)
je 0x20292
movq -0x2128(%rbp), %rdx
leaq -0x120(%rbp), %rdi
leaq -0x2120(%rbp), %rsi
callq 0x16d50
jmp 0x20290
jmp 0x20239
movq -0x70(%rbp), %rdi
callq 0x3350
jmp 0x2029d
leaq -0x120(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x16f70
jmp 0x202af
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
movq -0x30(%rbp), %rcx
leaq -0x50(%rbp), %r8
callq 0x1f960
jmp 0x202c9
movl $0x0, -0x80(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x7270
movl -0x80(%rbp), %eax
testl %eax, %eax
je 0x202e4
jmp 0x202e2
jmp 0x2030b
jmp 0x202f9
leaq 0xf2a3(%rip), %rdi      # 0x2f590
addq $0xb0, %rdi
callq 0x74e0
movq -0x8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
movl $0x10, %edx
callq 0x16d50
addq $0x2140, %rsp           # imm = 0x2140
popq %rbp
retq
movq -0x78(%rbp), %rdi
callq 0x35c0
nopl (%rax)