// File: /workspace/github_c_makefile_star2_O3/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 0x6792
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 0xf84d(%rip), %rdi      # 0x15fe6
callq 0x3400
testq %rax, %rax
je 0x67c5
leaq 0xf0(%rsp), %r14
movl $0x200, %edx            # imm = 0x200
movq %r14, %rdi
movq %rax, %rsi
callq 0x31a0
movb $0x0, 0x1ff(%r14)
jmp 0x6806
callq 0x5eb4
leaq 0x2f0(%rsp), %r14
movq %r14, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0xeb0c
movq %r14, %rdi
callq 0xed49
leaq 0xf807(%rip), %rsi      # 0x15ff5
movq %r14, %rdi
callq 0xed69
leaq 0xf0(%rsp), %rdi
movq %r14, %rsi
callq 0xee8e
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 0xf7a8(%rip), %rax      # 0x15ffc
movq %rax, 0x10(%rsp)
movq %r14, 0x18(%rsp)
leaq 0xf7af(%rip), %rdi      # 0x16014
callq 0x3400
movq %rax, %rbx
testq %rax, %rax
jne 0x68cb
leaq 0xf0(%rsp), %r15
movq %r15, %rdi
movl $0x20, %esi
callq 0x3130
testq %rax, %rax
leaq 0xfb05(%rip), %rax      # 0x16396
leaq 0xf4e3(%rip), %rcx      # 0x15d7b
cmoveq %rax, %rcx
movq %r14, (%rsp)
leaq 0xf78c(%rip), %rdx      # 0x16033
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 0x5d66
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 0x11ff1
movq %rax, %r14
testl %r14d, %r14d
je 0x690e
leaq 0xf73e(%rip), %rsi      # 0x1603d
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x5d74
testl %r14d, %r14d
sete %al
addq $0xaf0, %rsp            # imm = 0xAF0
popq %rbx
popq %r14
popq %r15
retq