// File: /workspace/github_c_makefile_star2_O1/deplinenoise[P]tundra/src/DagGenerator.cpp
// Function: t2::GenerateDag(char const*, char const*)
bool GenerateDag(const char* script_fn, const char* dag_fn)
{
  Log(kDebug, "regenerating DAG data");

  char json_filename[kMaxPathLength];
  snprintf(json_filename, sizeof json_filename, "%s.json", dag_fn);
  json_filename[sizeof(json_filename)- 1] = '\0';

  // Nuke any old JSON data.
  remove(json_filename);

  // Run DAG generator.
  if (!RunExternalTool("generate-dag %s %s", script_fn, json_filename))
    return false;

  FileInfo json_info = GetFileInfo(json_filename);
  if (!json_info.Exists())
  {
    Log(kError, "build script didn't generate %s", json_filename);
    return false;
  }

  size_t json_size = size_t(json_info.m_Size + 1);
  char* json_memory = (char*) malloc(json_size);
  if (!json_memory)
    Croak("couldn't allocate memory for JSON buffer");

  FILE* f = fopen(json_filename, "rb");
  if (!f)
  {
    free(json_memory);
    Log(kError, "couldn't open %s for reading", json_filename);
    return false;
  }

  size_t read_count = fread(json_memory, 1, json_size - 1, f);
  if (json_size - 1 != read_count)
  {
    fclose(f);
    free(json_memory);
    Log(kError, "couldn't read JSON data (%d bytes read out of %d)",
        json_filename, (int) read_count, (int) json_size);
    return false;
  }

  fclose(f);

  json_memory[json_size-1] = 0;

  bool success = CreateDagFromJsonData(json_memory, dag_fn);

  free(json_memory);

  return success;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x6b8, %rsp            # imm = 0x6B8
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xf8c1(%rip), %rsi      # 0x15ef9
xorl %ebp, %ebp
movl $0x8, %edi
xorl %eax, %eax
callq 0x5ef0
leaq 0xf8c2(%rip), %rdx      # 0x15f0f
leaq 0xb0(%rsp), %r15
movl $0x200, %esi            # imm = 0x200
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x3560
movb $0x0, 0x1ff(%r15)
movq %r15, %rdi
callq 0x3600
leaq 0xf899(%rip), %rdi      # 0x15f17
movq %rbx, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x68b8
testb %al, %al
je 0x67fc
leaq 0x28(%rsp), %rbx
leaq 0xb0(%rsp), %rsi
movq %rbx, %rdi
callq 0xdd8c
testb $0x1, (%rbx)
jne 0x66b9
leaq 0xf876(%rip), %rsi      # 0x15f2a
jmp 0x67e6
movq 0x30(%rsp), %r12
leaq 0x1(%r12), %r15
movq %r15, %rdi
callq 0x3440
testq %rax, %rax
je 0x68aa
movq %rax, %rbx
leaq 0xf895(%rip), %rsi      # 0x15f73
leaq 0xb0(%rsp), %rdi
callq 0x33c0
testq %rax, %rax
je 0x67d7
movq %rax, %rbp
movl $0x1, %esi
movq %rbx, %rdi
movq %r12, %rdx
movq %rax, %rcx
callq 0x34e0
movq %rax, %r13
movq %rbp, %rdi
callq 0x3340
cmpq %r13, %r12
jne 0x6810
movb $0x0, (%rbx,%r12)
leaq 0x7(%rsp), %r15
movq %r15, %rdi
callq 0xef60
leaq 0xf936(%rip), %rcx      # 0x1606d
leaq 0x78(%rsp), %r12
movl $0x8000000, %edx        # imm = 0x8000000
movq %r12, %rdi
movq %r15, %rsi
callq 0xefb4
leaq 0xf925(%rip), %rcx      # 0x16078
leaq 0x40(%rsp), %r13
movl $0x4000000, %edx        # imm = 0x4000000
movq %r13, %rdi
movq %r15, %rsi
callq 0xefb4
leaq 0x2b0(%rsp), %rcx
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xe338
testq %rax, %rax
je 0x683d
movq %rax, %r15
cmpl $0x2, (%rax)
jne 0x685c
leaq 0x8(%rsp), %r12
leaq 0x7(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x13bf4
leaq 0x40(%rsp), %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x6cca
testb %al, %al
je 0x6873
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x13ccc
movl %eax, %ebp
jmp 0x6875
movq %rbx, %rdi
callq 0x33d0
leaq 0xf790(%rip), %rsi      # 0x15f76
xorl %ebp, %ebp
leaq 0xb0(%rsp), %rdx
movl $0x1, %edi
xorl %eax, %eax
callq 0x5ef0
movl %ebp, %eax
addq $0x6b8, %rsp            # imm = 0x6B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x33d0
leaq 0xf774(%rip), %rsi      # 0x15f93
xorl %ebp, %ebp
leaq 0xb0(%rsp), %rdx
movl $0x1, %edi
movl %r13d, %ecx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x5ef0
jmp 0x67fc
leaq 0xf854(%rip), %rsi      # 0x16098
xorl %ebp, %ebp
leaq 0x2b0(%rsp), %rdx
movl $0x1, %edi
xorl %eax, %eax
callq 0x5ef0
jmp 0x687f
leaq 0xf822(%rip), %rsi      # 0x16085
xorl %ebp, %ebp
movl $0x1, %edi
xorl %eax, %eax
callq 0x5ef0
jmp 0x687f
xorl %ebp, %ebp
leaq 0x8(%rsp), %rdi
callq 0x13c07
leaq 0x40(%rsp), %rdi
callq 0xf012
leaq 0x78(%rsp), %rdi
callq 0xf012
leaq 0x7(%rsp), %rdi
callq 0xef61
movq %rbx, %rdi
callq 0x33d0
jmp 0x67fc
leaq 0xf699(%rip), %rdi      # 0x15f4a
xorl %eax, %eax
callq 0x5bdd