#!/usr/bin/env bash
# Long batch for the no-fence mutant: N trials (default 1000) of 2 threads x
# 100000 push/pop pairs under ASan. Output: results/nofence_batch.txt
set -euo pipefail
cd "$(dirname "$0")"
MT_CPUS=${MT_CPUS:-0,1}
N=${N:-1000}
BUILD_DIR=${BUILD_DIR:-$(mktemp -d)}
mkdir -p results "$BUILD_DIR"
gcc -std=c11 -Wall -Wextra -pthread -O1 -g -fsanitize=address,undefined -DHP_NO_FENCE=1 \
    hp_stack.c -o "$BUILD_DIR/asan_nofence"
: > results/nofence_batch.txt
for i in $(seq "$N"); do
  out=$(taskset -c "$MT_CPUS" "$BUILD_DIR/asan_nofence" -t 2 -n 100000 -R 1 2>&1 || true)
  rep=$(grep -m1 -oE 'AddressSanitizer: [a-z-]+' <<<"$out" || true)
  echo "trial=$i report=${rep:-none}" >> results/nofence_batch.txt
done
grep -c 'report=none' results/nofence_batch.txt | sed 's/^/clean=/'
