static int writeFile(FILE *File) {
  const char *BufferSzStr = 0;
  uint64_t ValueDataSize = 0;
  struct ValueProfData **ValueDataArray =
      __llvm_profile_gather_value_data(&ValueDataSize);
  FreeHook = &free;
  CallocHook = &calloc;
  BufferSzStr = getenv("LLVM_VP_BUFFER_SIZE");
  if (BufferSzStr && BufferSzStr[0])
    VPBufferSize = atoi(BufferSzStr);
  return lprofWriteData(fileWriter, File, ValueDataArray, ValueDataSize);
}
/* Write profile data to file \c OutputName.  */
static int writeFile(const char *OutputName) {
    int RetVal;
    FILE *OutputFile;

    if (!doMerging())
        OutputFile = fopen(OutputName, "ab");
    else
        OutputFile = openFileForMerging(OutputName);

    if (!OutputFile)
        return -1;

    FreeHook = &free;
    setupIOBuffer();
    RetVal = lprofWriteData(fileWriter, OutputFile, lprofGetVPDataReader());

    fclose(OutputFile);
    return RetVal;
}
static int dump(void) {
  if (lprofProfileDumped()) {
    lprofWrite("Profile data not published: already written.\n");
    return 0;
  }

  /* Check if there is llvm/runtime version mismatch. */
  if (GET_VERSION(__llvm_profile_get_version()) != INSTR_PROF_RAW_VERSION) {
    lprofWrite("Runtime and instrumentation version mismatch : "
               "expected %d, but got %d\n",
               INSTR_PROF_RAW_VERSION,
               (int)GET_VERSION(__llvm_profile_get_version()));
    return -1;
  }

  /* Write the profile data into the mapped region. */
  ProfDataWriter VMOWriter;
  initVMOWriter(&VMOWriter);
  if (lprofWriteData(&VMOWriter, lprofGetVPDataReader(), 0) != 0)
    return -1;

  return 0;
}
COMPILER_RT_VISIBILITY int __llvm_profile_write_buffer(char *Buffer) {
  ProfDataWriter BufferWriter;
  initBufferWriter(&BufferWriter, Buffer);
  return lprofWriteData(&BufferWriter, 0, 0);
}
static int writeFile(FILE *File) {
  FreeHook = &free;
  setupIOBuffer();
  return lprofWriteData(fileWriter, File, lprofGetVPDataReader());
}