TMP=/usr/tmp/ego
DDUMP=$TMP.dd.$$
PDUMP=$TMP.pd.$$
PHASES=''
FLAGS=''
LEVEL=xxx
EM=$1
KEEPTEMPS=no
shift


while :
do
        case $# in
        0)      break ;;
        esac
        A="$1"
        shift
        case $A in
	*.m|*.ma) ICARG="$ICARG $A"; continue;;
	-P)	OPT="$1"; shift; continue;;
	-IL)	PHASES="$PHASES il cf caopt ic cf " ; continue;;
	-CS)	PHASES="$PHASES cs " ; continue;;
	-SR)	PHASES="$PHASES sr " ; continue;;
	-UD)	PHASES="$PHASES ud " ; continue;;
	-LV)	PHASES="$PHASES lv " ; continue;;
	-RA)	PHASES="$PHASES ra " ; continue;;
	-SP)	PHASES="$PHASES sp " ; continue;;
	-BO)	PHASES="$PHASES bo " ; continue;;
	-CJ)	PHASES="$PHASES cj " ; continue;;
	-O*)	LEVEL=$A ; continue;;
	-t)	KEEPTEMPS=yes ; continue;;
	-*)	FLAGS="$FLAGS $A"; continue;;
	esac
done
if test "$PHASES"
then :
else
	case $LEVEL in
	-O2|-O|xxx)PHASES='cj bo sp ' ;;
	-O3)	PHASES='cs sr cj bo sp ud lv ra ' ;;
	*)	PHASES='il cf caopt ic cf cs sr cj bo sp ud lv ra ' ;;
	esac
fi
TMPOPT=$TMP.o.$$
PASSES="ic cf $PHASES ca"
OUTFILES="$PDUMP $DDUMP"
FILES="$OUTFILES $TMPOPT"
c=1
if test "$ICARG"
then :
else
exit 0
fi
for i in $PASSES
do	INFILES=$OUTFILES
	OUTFILES="$TMP.p.$c.$$ $TMP.d.$c.$$ $TMP.l.$c.$$ $TMP.b.$c.$$"
	FILES="$FILES $OUTFILES"
	if [ $KEEPTEMPS = no ]
	then
		trap "rm -f $FILES; exit 1" 0 1 2 15
	fi
	case $i in
	ic)	$OPT/ic $INFILES - - $OUTFILES $ICARG || exit 1
		;;
	ca)	$OPT/ca $INFILES $PDUMP $DDUMP - - || exit 1
		;;
	caopt)	rm -f $TMPOPT
		$OPT/ca $INFILES $PDUMP $DDUMP - - | $EM/lib/em_opt2 > $TMPOPT || exit 1
		ICARG=$TMPOPT
		OUTFILES="$PDUMP $DDUMP"
		if [ $KEEPTEMPS = no ]
		then
			rm -f $INFILES $PDUMP $DDUMP
		fi
		;;
	*)	$OPT/$i $INFILES $OUTFILES $FLAGS || exit 1
		if [ $KEEPTEMPS = no ]
		then
			rm -f $INFILES
		fi
		;;
	esac
	c=`expr $c + 1`
done
if [ $KEEPTEMPS = no ]
then
	rm -f $FILES
fi
trap 0
exit 0
