#!/usr/bin/env perl
##
## Copyright (c) 2012 The University of Utah
## All rights reserved.
##
## This file is distributed under the University of Illinois Open Source
## License.  See the file COPYING for details.

###############################################################################

### this script preps a testcase for reduction and calls the result
### small.c; it takes the same arguments as Csmith

use strict;
use warnings;

my $CSMITH_HOME = $ENV{"CSMITH_HOME"};
die if (!defined($CSMITH_HOME));

my $CREDUCE_HOME = $ENV{"CREDUCE_HOME"};
die if (!defined($CREDUCE_HOME));

my $outfile = "orig_csmith_output.c";
for (my $i=0; $i<scalar(@ARGV); $i++) {
    if ($ARGV[$i] eq "--output") {
	$outfile = $ARGV[$i+1];
    }
}
die if (!defined($outfile)); 

system "${CSMITH_HOME}/src/csmith @ARGV";

system "gcc -E -I${CSMITH_HOME}/runtime -DCSMITH_MINIMAL $outfile | ${CREDUCE_HOME}/scripts/shorten > small.c";

system "indent small.c";
