// File: /workspace/github_c_makefile_star2_O2/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 0x6278
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 0xdd65(%rip), %rdi      # 0x13fe4
callq 0x3400
testq %rax, %rax
je 0x62ab
leaq 0xf0(%rsp), %r14
movl $0x200, %edx            # imm = 0x200
movq %r14, %rdi
movq %rax, %rsi
callq 0x31a0
movb $0x0, 0x1ff(%r14)
jmp 0x62ec
callq 0x5abf
leaq 0x2f0(%rsp), %r14
movq %r14, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0xda18
movq %r14, %rdi
callq 0xdc55
leaq 0xdd1f(%rip), %rsi      # 0x13ff3
movq %r14, %rdi
callq 0xdc75
leaq 0xf0(%rsp), %rdi
movq %r14, %rsi
callq 0xdd8e
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 0xdcc0(%rip), %rax      # 0x13ffa
movq %rax, 0x10(%rsp)
movq %r14, 0x18(%rsp)
leaq 0xdcc7(%rip), %rdi      # 0x14012
callq 0x3400
movq %rax, %rbx
testq %rax, %rax
jne 0x63af
leaq 0xf0(%rsp), %r15
pushq $0x20
popq %rsi
movq %r15, %rdi
callq 0x3130
testq %rax, %rax
leaq 0xe01f(%rip), %rax      # 0x14394
leaq 0xda17(%rip), %rcx      # 0x13d93
cmoveq %rax, %rcx
movq %r14, (%rsp)
leaq 0xdca6(%rip), %rdx      # 0x14031
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 0x5973
shrl $0x3, %eax
andl $0x1, %eax
pushq $0x1
popq %rsi
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
movl %eax, %r8d
xorl %r9d, %r9d
callq 0x10965
movq %rax, %r14
testl %r14d, %r14d
je 0x63ee
leaq 0xdc5a(%rip), %rsi      # 0x1403b
pushq $0x1
popq %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x5981
testl %r14d, %r14d
sete %al
addq $0xaf0, %rsp            # imm = 0xAF0
popq %rbx
popq %r14
popq %r15
retq