#! /bin/sh
###########################################################################
#
# Name
#    coopt.sh -- an inefficient optimizer that can produce very efficient
#                code
#
# DESCRIPTION
#    This optimizer is only run on noninteractive code that takes no
#    output. (It's designed to run on executables produced by INTERCAL
#    code, but will run on other executables that support the +mystery
#    option). It optimizes the file by replacing it by one that simply
#    produces the required output! Therefore, it creates fast but
#    inefficient code. If the file to be optimized hits an error or
#    is terminated by +mystery, then no changes are made.
#
# SPDX-FileCopyrightText: (C) Alex Smith
# SPDX-License-Identifier: GPL-2.0-or-later
#
###########################################################################

rm -f icktemp.out >/dev/null 2>/dev/null
if `readlink -f $1@EXEEXT@` +mystery >icktemp.out 2>/dev/null ; then : ; else
echo Execution of $1@EXEEXT@ failed.
rm -f icktemp.out ; exit 0 ; fi
rm $1@EXEEXT@
echo '#! /bin/sh
tail -n+3 $0; exit 0' | cat - icktemp.out > $1@EXEEXT@
chmod +x $1@EXEEXT@
rm -f icktemp.out
exit 0
