// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x260, %rsp            # imm = 0x260
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x8, %edi
leaq 0x1b9a0(%rip), %rsi     # 0x23f0f
movb $0x0, %al
callq 0x7a60
leaq -0x220(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x200, %esi            # imm = 0x200
leaq 0x1b998(%rip), %rdx     # 0x23f25
movb $0x0, %al
callq 0x3540
movb $0x0, -0x21(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x35e0
movq -0x10(%rbp), %rsi
leaq -0x220(%rbp), %rdx
leaq 0x1b977(%rip), %rdi     # 0x23f2d
movb $0x0, %al
callq 0x8790
testb $0x1, %al
jne 0x85ca
movb $0x0, -0x1(%rbp)
jmp 0x877a
leaq -0x220(%rbp), %rsi
leaq -0x238(%rbp), %rdi
callq 0x16920
leaq -0x238(%rbp), %rdi
callq 0x71b0
testb $0x1, %al
jne 0x8610
leaq -0x220(%rbp), %rdx
movl $0x1, %edi
leaq 0x1b940(%rip), %rsi     # 0x23f40
movb $0x0, %al
callq 0x7a60
movb $0x0, -0x1(%rbp)
jmp 0x877a
movq -0x230(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x240(%rbp)
movq -0x240(%rbp), %rdi
callq 0x3440
movq %rax, -0x248(%rbp)
cmpq $0x0, -0x248(%rbp)
jne 0x864d
leaq 0x1b91a(%rip), %rdi     # 0x23f60
movb $0x0, %al
callq 0x75a0
leaq -0x220(%rbp), %rdi
leaq 0x1b92e(%rip), %rsi     # 0x23f89
callq 0x33c0
movq %rax, -0x250(%rbp)
cmpq $0x0, -0x250(%rbp)
jne 0x86a0
movq -0x248(%rbp), %rdi
callq 0x33d0
leaq -0x220(%rbp), %rdx
movl $0x1, %edi
leaq 0x1b8fc(%rip), %rsi     # 0x23f8c
movb $0x0, %al
callq 0x7a60
movb $0x0, -0x1(%rbp)
jmp 0x877a
movq -0x248(%rbp), %rdi
movq -0x240(%rbp), %rdx
subq $0x1, %rdx
movq -0x250(%rbp), %rcx
movl $0x1, %esi
callq 0x34d0
movq %rax, -0x258(%rbp)
movq -0x240(%rbp), %rax
subq $0x1, %rax
cmpq -0x258(%rbp), %rax
je 0x8729
movq -0x250(%rbp), %rdi
callq 0x3350
movq -0x248(%rbp), %rdi
callq 0x33d0
leaq -0x220(%rbp), %rdx
movq -0x258(%rbp), %rax
movl %eax, %ecx
movq -0x240(%rbp), %rax
movl %eax, %r8d
movl $0x1, %edi
leaq 0x1b88d(%rip), %rsi     # 0x23fa9
movb $0x0, %al
callq 0x7a60
movb $0x0, -0x1(%rbp)
jmp 0x877a
movq -0x250(%rbp), %rdi
callq 0x3350
movq -0x248(%rbp), %rax
movq -0x240(%rbp), %rcx
subq $0x1, %rcx
movb $0x0, (%rax,%rcx)
movq -0x248(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x8a30
andb $0x1, %al
movb %al, -0x259(%rbp)
movq -0x248(%rbp), %rdi
callq 0x33d0
movb -0x259(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
nopl (%rax,%rax)