// File: /workspace/github_c_makefile_star2_O3/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 0xfa40(%rip), %rsi      # 0x15ee9
xorl %ebp, %ebp
movl $0x8, %edi
xorl %eax, %eax
callq 0x5d74
leaq 0xfa41(%rip), %rdx      # 0x15eff
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 0xfa18(%rip), %rdi      # 0x15f07
movq %rbx, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x6729
testb %al, %al
je 0x666d
leaq 0x28(%rsp), %rbx
leaq 0xb0(%rsp), %rsi
movq %rbx, %rdi
callq 0xd860
testb $0x1, (%rbx)
jne 0x652a
leaq 0xf9f5(%rip), %rsi      # 0x15f1a
jmp 0x6657
movq 0x30(%rsp), %r12
leaq 0x1(%r12), %r15
movq %r15, %rdi
callq 0x3440
testq %rax, %rax
je 0x671b
movq %rax, %rbx
leaq 0xfa14(%rip), %rsi      # 0x15f63
leaq 0xb0(%rsp), %rdi
callq 0x33c0
testq %rax, %rax
je 0x6648
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 0x6681
movb $0x0, (%rbx,%r12)
leaq 0x7(%rsp), %r15
movq %r15, %rdi
callq 0xe880
leaq 0xfab5(%rip), %rcx      # 0x1605d
leaq 0x78(%rsp), %r12
movl $0x8000000, %edx        # imm = 0x8000000
movq %r12, %rdi
movq %r15, %rsi
callq 0xe8d4
leaq 0xfaa4(%rip), %rcx      # 0x16068
leaq 0x40(%rsp), %r13
movl $0x4000000, %edx        # imm = 0x4000000
movq %r13, %rdi
movq %r15, %rsi
callq 0xe8d4
leaq 0x2b0(%rsp), %rcx
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xde64
testq %rax, %rax
je 0x66ae
movq %rax, %r15
cmpl $0x2, (%rax)
jne 0x66cd
leaq 0x8(%rsp), %r12
leaq 0x7(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x134bc
leaq 0x40(%rsp), %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x6b3b
testb %al, %al
je 0x66e4
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x1359a
movl %eax, %ebp
jmp 0x66e6
movq %rbx, %rdi
callq 0x33d0
leaq 0xf90f(%rip), %rsi      # 0x15f66
xorl %ebp, %ebp
leaq 0xb0(%rsp), %rdx
movl $0x1, %edi
xorl %eax, %eax
callq 0x5d74
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 0xf8f3(%rip), %rsi      # 0x15f83
xorl %ebp, %ebp
leaq 0xb0(%rsp), %rdx
movl $0x1, %edi
movl %r13d, %ecx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x5d74
jmp 0x666d
leaq 0xf9d3(%rip), %rsi      # 0x16088
xorl %ebp, %ebp
leaq 0x2b0(%rsp), %rdx
movl $0x1, %edi
xorl %eax, %eax
callq 0x5d74
jmp 0x66f0
leaq 0xf9a1(%rip), %rsi      # 0x16075
xorl %ebp, %ebp
movl $0x1, %edi
xorl %eax, %eax
callq 0x5d74
jmp 0x66f0
xorl %ebp, %ebp
leaq 0x8(%rsp), %rdi
callq 0x134cf
leaq 0x40(%rsp), %rdi
callq 0xe932
leaq 0x78(%rsp), %rdi
callq 0xe932
leaq 0x7(%rsp), %rdi
callq 0xe881
movq %rbx, %rdi
callq 0x33d0
jmp 0x666d
leaq 0xf818(%rip), %rdi      # 0x15f3a
xorl %eax, %eax
callq 0x5a61