#!/bin/bash

cvc5=$(dirname "$(readlink -f "$0")")/cvc5
bench="$1"

# Output other than "sat"/"unsat" is either written to stderr or to "err.log"
# in the directory specified by $2 if it has been set (e.g. when running on
# StarExec).
out_file=/dev/stderr

if [ -n "$STAREXEC_WALLCLOCK_LIMIT" ]; then
  # If we are running on StarExec, don't print to `/dev/stderr/` even when $2
  # is not provided.
  out_file="/dev/null"
fi

if [ -n "$2" ]; then
  out_file="$2/err.log"
fi

result="$({ $cvc5 -L smt2.6 --no-incremental --no-type-checking --no-interactive --fp-exp --use-portfolio $bench; } 2>&1)"
case "$result" in
  sat|unsat) echo "$result"; exit 0;;
  *)         echo "$result" &> "$out_file";;
esac

