// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]tundra/src/Driver.cpp
// Function: t2::DriverBuild(t2::Driver*)
BuildResult::Enum DriverBuild(Driver* self)
{
  const DagData* dag = self->m_DagData;
  const int pass_count = dag->m_Passes.GetCount();

#if ENABLED(CHECKED_BUILD)
  // Do some paranoia checking of the node state to make sure pass indices are
  // set up correctly.
  {
    ProfilerScope prof_scope("Tundra DebugCheckPassIndices", 0);
    int i = 0;
    for (int pass = 0; pass < pass_count; ++pass)
    {
      for (int n = 0, node_count = self->m_PassNodeCount[pass]; n < node_count; ++n)
      {
        CHECK(self->m_Nodes[i].m_PassIndex == pass);
        ++i;
      }
    }
    CHECK(size_t(i) == self->m_Nodes.m_Size);
  }
#endif

  // Initialize build queue
  Mutex debug_signing_mutex;

  int max_expensive_count = self->m_DagData->m_MaxExpensiveCount;

  if (max_expensive_count < 0)
    max_expensive_count = self->m_Options.m_ThreadCount;
  else
    max_expensive_count = std::max(std::min(max_expensive_count, self->m_Options.m_ThreadCount), 1);

  Log(kDebug, "Max # expensive jobs: %d", max_expensive_count);

  BuildQueueConfig queue_config;
  queue_config.m_Flags                   = 0;
  queue_config.m_Heap                    = &self->m_Heap;
  queue_config.m_ThreadCount             = (int) self->m_Options.m_ThreadCount;
  queue_config.m_NodeData                = self->m_DagData->m_NodeData;
  queue_config.m_NodeState               = self->m_Nodes.m_Storage;
  queue_config.m_MaxNodes                = (int) self->m_Nodes.m_Size;
  queue_config.m_NodeRemappingTable      = self->m_NodeRemap.m_Storage;
  queue_config.m_ScanCache               = &self->m_ScanCache;
  queue_config.m_StatCache               = &self->m_StatCache;
  queue_config.m_DigestCache             = &self->m_DigestCache;
  queue_config.m_ShaDigestExtensionCount = dag->m_ShaExtensionHashes.GetCount();
  queue_config.m_ShaDigestExtensions     = dag->m_ShaExtensionHashes.GetArray();
  queue_config.m_MaxExpensiveCount       = max_expensive_count;

  if (self->m_Options.m_Verbose)
  {
    queue_config.m_Flags |= BuildQueueConfig::kFlagEchoAnnotations | BuildQueueConfig::kFlagEchoCommandLines;
  }
  if (!self->m_Options.m_Quiet)
  {
    queue_config.m_Flags |= BuildQueueConfig::kFlagEchoAnnotations;
  }
  if (self->m_Options.m_ContinueOnError)
  {
    queue_config.m_Flags |= BuildQueueConfig::kFlagContinueOnError;
  }

  if (self->m_Options.m_DebugSigning)
  {
    MutexInit(&debug_signing_mutex);
    queue_config.m_FileSigningLogMutex = &debug_signing_mutex;
    queue_config.m_FileSigningLog      = fopen("signing-debug.txt", "w");
  }
  else
  {
    queue_config.m_FileSigningLogMutex = nullptr;
    queue_config.m_FileSigningLog      = nullptr;
  }

#if ENABLED(CHECKED_BUILD)
  {
    ProfilerScope prof_scope("Tundra DebugCheckRemap", 0);
    // Paranoia - double check node remapping table
    for (size_t i = 0, count = self->m_Nodes.m_Size; i < count; ++i)
    {
      const NodeState* state = self->m_Nodes.m_Storage + i;
      const NodeData* src = state->m_MmapData;
      const int src_index = int(src - self->m_DagData->m_NodeData);
      int remapped_index = self->m_NodeRemap[src_index];
      CHECK(size_t(remapped_index) == i);
    }
  }
#endif


  BuildQueue build_queue;
  BuildQueueInit(&build_queue, &queue_config);

  int global_node_index = 0;

  BuildResult::Enum build_result = BuildResult::kOk;

  for (int pass = 0; BuildResult::kOk == build_result && pass < pass_count; ++pass)
  {
    const char *pass_name  = dag->m_Passes[pass].m_PassName;
    const int   pass_nodes = self->m_PassNodeCount[pass];

    Log(kInfo, "begin pass %s (nodes: %d - %d (%d))",
        pass_name, global_node_index, global_node_index + pass_nodes - 1, pass_nodes);

    build_result = BuildQueueBuildNodeRange(&build_queue, global_node_index, pass_nodes, pass);

    global_node_index += pass_nodes;

    Log(kInfo, "end pass %s", pass_name);
  }

  if (self->m_Options.m_DebugSigning)
  {
    fclose((FILE*)queue_config.m_FileSigningLog);
    MutexDestroy(&debug_signing_mutex);
  }

  // Shut down build queue
  BuildQueueDestroy(&build_queue);

  return build_result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
callq 0x14860
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rax
movl 0x68(%rax), %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jge 0xe904
movq -0x8(%rbp), %rax
movl 0xc8(%rax), %eax
movl %eax, -0x44(%rbp)
jmp 0xe934
movq -0x8(%rbp), %rsi
addq $0xb8, %rsi
addq $0x10, %rsi
leaq -0x44(%rbp), %rdi
callq 0x148b0
movq %rax, %rdi
movl $0x1, -0x48(%rbp)
leaq -0x48(%rbp), %rsi
callq 0x14870
movl (%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %edx
movl $0x8, %edi
leaq 0x15da1(%rip), %rsi     # 0x246e4
movb $0x0, %al
callq 0x7a60
movl $0x0, -0xc0(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x8(%rbp), %rax
movl 0xc8(%rax), %eax
movl %eax, -0xb0(%rbp)
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
addq $0xc, %rdi
callq 0x144d0
movq %rax, -0xa8(%rbp)
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0x8(%rbp), %rax
movq 0x108(%rax), %rax
movl %eax, -0x98(%rbp)
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rax
addq $0x150, %rax            # imm = 0x150
movq %rax, -0x88(%rbp)
movq -0x8(%rbp), %rax
addq $0x1f0, %rax            # imm = 0x1F0
movq %rax, -0x80(%rbp)
movq -0x8(%rbp), %rax
addq $0x268, %rax            # imm = 0x268
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
addq $0x60, %rdi
callq 0x148f0
movl %eax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
addq $0x60, %rdi
callq 0x14900
movq %rax, -0x68(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rax
testb $0x1, 0xbd(%rax)
je 0xea2f
movl -0xc0(%rbp), %eax
orl $0x3, %eax
movl %eax, -0xc0(%rbp)
movq -0x8(%rbp), %rax
testb $0x1, 0xc1(%rax)
jne 0xea4b
movl -0xc0(%rbp), %eax
orl $0x2, %eax
movl %eax, -0xc0(%rbp)
movq -0x8(%rbp), %rax
testb $0x1, 0xc6(%rax)
je 0xea67
movl -0xc0(%rbp), %eax
orl $0x4, %eax
movl %eax, -0xc0(%rbp)
movq -0x8(%rbp), %rax
testb $0x1, 0xc5(%rax)
je 0xea9e
leaq -0x40(%rbp), %rdi
callq 0x6810
leaq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq 0x15c71(%rip), %rdi     # 0x246fd
leaq 0x15aa8(%rip), %rsi     # 0x2453b
callq 0x33c0
movq %rax, -0x60(%rbp)
jmp 0xeaae
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
leaq -0x1e0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x45f0
movl $0x0, -0x1e4(%rbp)
movl $0x0, -0x1e8(%rbp)
movl $0x0, -0x1ec(%rbp)
xorl %eax, %eax
xorl %ecx, %ecx
cmpl -0x1e8(%rbp), %ecx
movb %al, -0x1fd(%rbp)
jne 0xeb03
movl -0x1ec(%rbp), %eax
cmpl -0x14(%rbp), %eax
setl %al
movb %al, -0x1fd(%rbp)
movb -0x1fd(%rbp), %al
testb $0x1, %al
jne 0xeb12
jmp 0xebe9
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
movl -0x1ec(%rbp), %esi
callq 0x14920
movq %rax, %rdi
callq 0x6e20
movq %rax, -0x1f8(%rbp)
movq -0x8(%rbp), %rax
movslq -0x1ec(%rbp), %rcx
movl 0x340(%rax,%rcx,4), %eax
movl %eax, -0x1fc(%rbp)
movq -0x1f8(%rbp), %rdx
movl -0x1e4(%rbp), %ecx
movl -0x1e4(%rbp), %r8d
addl -0x1fc(%rbp), %r8d
subl $0x1, %r8d
movl -0x1fc(%rbp), %r9d
movl $0x4, %edi
leaq 0x15b91(%rip), %rsi     # 0x2470f
movb $0x0, %al
callq 0x7a60
movl -0x1e4(%rbp), %esi
movl -0x1fc(%rbp), %edx
movl -0x1ec(%rbp), %ecx
leaq -0x1e0(%rbp), %rdi
callq 0x4b80
movl %eax, -0x1e8(%rbp)
movl -0x1fc(%rbp), %eax
addl -0x1e4(%rbp), %eax
movl %eax, -0x1e4(%rbp)
movq -0x1f8(%rbp), %rdx
movl $0x4, %edi
leaq 0x15b65(%rip), %rsi     # 0x24733
movb $0x0, %al
callq 0x7a60
movl -0x1ec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1ec(%rbp)
jmp 0xeadf
movq -0x8(%rbp), %rax
testb $0x1, 0xc5(%rax)
je 0xec08
movq -0x60(%rbp), %rdi
callq 0x3350
leaq -0x40(%rbp), %rdi
callq 0x6ab0
leaq -0x1e0(%rbp), %rdi
callq 0x4980
movl -0x1e8(%rbp), %eax
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
nopw %cs:(%rax,%rax)