/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#include <cassert>
#include <cstring>
#include <fstream>
#include <iostream>
#include <string>

#include "se_defines.h"

SE_GLOBALS()

void test_case(std::string content) {
  for (int i = 0; i < 100; i++) {
    new char[0x20];
  }
  char* buffer1 = new char[0x20];
  char* buffer2 = new char[0x20];

  strcpy(buffer2, "BBBB");

  strcpy(buffer1, content.c_str());

  printf("buffer1: %p:%s\n", buffer1, buffer1);
  printf("buffer2: %p:%s\n", buffer2, buffer2);

  if (strcmp(buffer2, "BBBB")) {
    SE_STEP(true);
  }

  if (!strcmp(buffer2, "AAAA")) {
    SE_TARGET_STATE(true);
  }
}

int main(int argc, char* argv[]) {
  std::istream* input;
  std::ifstream file;
  if (argc < 2) {
    input = &std::cin; // No file name provided, read from stdin
  } else {
    file.open(argv[1]);
    if (!file) {
      std::cerr << "Could not open the file.\n";
      return 1;
    }
    input = &file; // File opened successfully, read from file
  }
  std::string content(
      (std::istreambuf_iterator<char>(*input)),
      std::istreambuf_iterator<char>());
  test_case(content);
  return 0;
}
