// File: /workspace/github_c_makefile_star2_O2/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 0xdf4c(%rip), %rsi      # 0x13ee7
xorl %ebp, %ebp
pushq $0x8
popq %rdi
xorl %eax, %eax
callq 0x5981
leaq 0xdf4f(%rip), %rdx      # 0x13efd
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 0xdf26(%rip), %rdi      # 0x13f05
movq %rbx, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x620f
testb %al, %al
je 0x6159
leaq 0x28(%rsp), %rbx
leaq 0xb0(%rsp), %rsi
movq %rbx, %rdi
callq 0xc948
testb $0x1, (%rbx)
jne 0x601a
leaq 0xdf03(%rip), %rsi      # 0x13f18
jmp 0x6145
movq 0x30(%rsp), %r12
leaq 0x1(%r12), %r15
movq %r15, %rdi
callq 0x3440
testq %rax, %rax
je 0x6201
movq %rax, %rbx
leaq 0xdf22(%rip), %rsi      # 0x13f61
leaq 0xb0(%rsp), %rdi
callq 0x33c0
testq %rax, %rax
je 0x6136
movq %rax, %rbp
pushq $0x1
popq %rsi
movq %rbx, %rdi
movq %r12, %rdx
movq %rax, %rcx
callq 0x34e0
movq %rax, %r13
movq %rbp, %rdi
callq 0x3340
cmpq %r13, %r12
jne 0x616d
movb $0x0, (%rbx,%r12)
leaq 0x7(%rsp), %r15
movq %r15, %rdi
callq 0xd798
leaq 0xdfc5(%rip), %rcx      # 0x1405b
leaq 0x78(%rsp), %r12
movl $0x8000000, %edx        # imm = 0x8000000
movq %r12, %rdi
movq %r15, %rsi
callq 0xd7ec
leaq 0xdfb4(%rip), %rcx      # 0x14066
leaq 0x40(%rsp), %r13
movl $0x4000000, %edx        # imm = 0x4000000
movq %r13, %rdi
movq %r15, %rsi
callq 0xd7ec
leaq 0x2b0(%rsp), %rcx
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xce90
testq %rax, %rax
je 0x6198
movq %rax, %r15
cmpl $0x2, (%rax)
jne 0x61b5
leaq 0x8(%rsp), %r12
leaq 0x7(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x11ba0
leaq 0x40(%rsp), %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x65e6
testb %al, %al
je 0x61ca
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x11c22
movl %eax, %ebp
jmp 0x61cc
movq %rbx, %rdi
callq 0x33d0
leaq 0xde1f(%rip), %rsi      # 0x13f64
xorl %ebp, %ebp
pushq $0x1
popq %rdi
leaq 0xb0(%rsp), %rdx
xorl %eax, %eax
callq 0x5981
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 0xde05(%rip), %rsi      # 0x13f81
xorl %ebp, %ebp
pushq $0x1
popq %rdi
leaq 0xb0(%rsp), %rdx
movl %r13d, %ecx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x5981
jmp 0x6159
leaq 0xdee7(%rip), %rsi      # 0x14086
xorl %ebp, %ebp
pushq $0x1
popq %rdi
leaq 0x2b0(%rsp), %rdx
xorl %eax, %eax
callq 0x5981
jmp 0x61d6
leaq 0xdeb7(%rip), %rsi      # 0x14073
xorl %ebp, %ebp
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x5981
jmp 0x61d6
xorl %ebp, %ebp
leaq 0x8(%rsp), %rdi
callq 0x11bb0
leaq 0x40(%rsp), %rdi
callq 0xd84a
leaq 0x78(%rsp), %rdi
callq 0xd84a
leaq 0x7(%rsp), %rdi
callq 0xd799
movq %rbx, %rdi
callq 0x33d0
jmp 0x6159
leaq 0xdd30(%rip), %rdi      # 0x13f38
xorl %eax, %eax
callq 0x56cd