// File: /workspace/github_c_makefile_star2_O1/deplinenoise[P]tundra/src/DagGenerator.cpp
// Function: t2::RunExternalTool(char const*, ...)
static bool RunExternalTool(const char* options, ...)
{
  char dag_gen_path[kMaxPathLength];

  if (const char* env_option = getenv("TUNDRA_DAGTOOL"))
  {
    strncpy(dag_gen_path, env_option, sizeof dag_gen_path);
    dag_gen_path[sizeof(dag_gen_path)-1] = '\0';
  }
  else
  {
    // Figure out the path to the default t2-lua DAG generator.
    PathBuffer pbuf;
    PathInit(&pbuf, GetExePath());
    PathStripLast(&pbuf);
    PathConcat(&pbuf, "t2-lua" TUNDRA_EXE_SUFFIX);
    PathFormat(dag_gen_path, &pbuf);
  }


  const char* cmdline_to_use;

  char option_str[1024];
  char cmdline[1024];
  va_list args;
  va_start(args, options);
  vsnprintf(option_str, sizeof option_str, options, args);
  va_end(args);
  option_str[sizeof(option_str)-1] = '\0';

  EnvVariable env_var;
  env_var.m_Name = "TUNDRA_FRONTEND_OPTIONS";
  env_var.m_Value = option_str;

  if (const char* env_option = getenv("TUNDRA_DAGTOOL_FULLCOMMANDLINE"))
  {
    cmdline_to_use = env_option;
  }
  else
  {
    const char* quotes = "";
    if (strchr(dag_gen_path, ' '))
      quotes = "\"";

    snprintf(cmdline, sizeof cmdline, "%s%s%s %s", quotes, dag_gen_path, quotes, option_str);
    cmdline[sizeof(cmdline)-1] = '\0';

    cmdline_to_use = cmdline;
  }

  const bool echo = (GetLogFlags() & kDebug) ? true : false;

  ExecResult result = ExecuteProcess(cmdline_to_use, 1, &env_var, 0, echo, nullptr);

  if (0 != result.m_ReturnCode)
  {
    Log(kError, "DAG generator driver failed: %s", cmdline_to_use);
    return false;
  }

  return true;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0xaf0, %rsp            # imm = 0xAF0
movq %rdi, %rbx
movq %rsi, 0x48(%rsp)
movq %rdx, 0x50(%rsp)
movq %rcx, 0x58(%rsp)
movq %r8, 0x60(%rsp)
movq %r9, 0x68(%rsp)
testb %al, %al
je 0x6921
movaps %xmm0, 0x70(%rsp)
movaps %xmm1, 0x80(%rsp)
movaps %xmm2, 0x90(%rsp)
movaps %xmm3, 0xa0(%rsp)
movaps %xmm4, 0xb0(%rsp)
movaps %xmm5, 0xc0(%rsp)
movaps %xmm6, 0xd0(%rsp)
movaps %xmm7, 0xe0(%rsp)
leaq 0xf6ce(%rip), %rdi      # 0x15ff6
callq 0x3400
testq %rax, %rax
je 0x6954
leaq 0xf0(%rsp), %r14
movl $0x200, %edx            # imm = 0x200
movq %r14, %rdi
movq %rax, %rsi
callq 0x31a0
movb $0x0, 0x1ff(%r14)
jmp 0x6995
callq 0x6030
leaq 0x2f0(%rsp), %r14
movq %r14, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0xf1ec
movq %r14, %rdi
callq 0xf42c
leaq 0xf688(%rip), %rsi      # 0x16005
movq %r14, %rdi
callq 0xf44c
leaq 0xf0(%rsp), %rdi
movq %r14, %rsi
callq 0xf56a
leaq 0x40(%rsp), %rax
leaq 0x20(%rsp), %rcx
movq %rax, 0x10(%rcx)
leaq 0xb10(%rsp), %rax
movq %rax, 0x8(%rcx)
movabsq $0x3000000008, %rax     # imm = 0x3000000008
movq %rax, (%rcx)
leaq 0x2f0(%rsp), %r14
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdi
movq %rbx, %rdx
callq 0x3200
movb $0x0, 0x3ff(%r14)
leaq 0xf629(%rip), %rax      # 0x1600c
movq %rax, 0x10(%rsp)
movq %r14, 0x18(%rsp)
leaq 0xf630(%rip), %rdi      # 0x16024
callq 0x3400
movq %rax, %rbx
testq %rax, %rax
jne 0x6a5a
leaq 0xf0(%rsp), %r15
movq %r15, %rdi
movl $0x20, %esi
callq 0x3130
testq %rax, %rax
leaq 0xf986(%rip), %rax      # 0x163a6
leaq 0xf36c(%rip), %rcx      # 0x15d93
cmoveq %rax, %rcx
movq %r14, (%rsp)
leaq 0xf60d(%rip), %rdx      # 0x16043
leaq 0x6f0(%rsp), %rbx
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq %r15, %r8
movq %rcx, %r9
xorl %eax, %eax
callq 0x3560
movb $0x0, 0x3ff(%rbx)
callq 0x5ee2
shrl $0x3, %eax
andl $0x1, %eax
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
movl $0x1, %esi
xorl %ecx, %ecx
movl %eax, %r8d
xorl %r9d, %r9d
callq 0x1272d
movq %rax, %r14
testl %r14d, %r14d
je 0x6a9d
leaq 0xf5bf(%rip), %rsi      # 0x1604d
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x5ef0
testl %r14d, %r14d
sete %al
addq $0xaf0, %rsp            # imm = 0xAF0
popq %rbx
popq %r14
popq %r15
retq