#!/bin/sh -e

version=`cat ../version`
tmp=../link-build/verify-$version

rm -rf $tmp
mkdir -p $tmp

for n in `seq 0 512`
do
  for lib in ../link-install/lib-*
  do
    c=`cat $lib/compiler`
    echo "verifying n=$n lib=$lib compiler=$c" >&2
  
    echo '
#include <stdio.h>
#include "int32_sort.h"
int32_t symbolic['$n'];
int main()
{
  long long i;
  int32_sort(symbolic,'$n');
  for (i = 0;i < '$n';++i) printf("%d\\n",symbolic[i]);
  return 0;
}
' > $tmp/symbolic.c
  
    time $c \
    -L $lib -Wl,-rpath=$lib \
    -I $lib/include \
    -o $tmp/symbolic $tmp/symbolic.c \
    -l djbsort
  
    time ./unroll symbolic $n $tmp/symbolic > $tmp/unroll
    time ./tryinput $n < $tmp/unroll > $tmp/input
    time /usr/pkg/bin/python3.13 $tmp/input
    time ./minmax $n < $tmp/unroll > $tmp/minmax
    time ./tryinput $n < $tmp/minmax > $tmp/input
    time /usr/pkg/bin/python3.13 $tmp/input
    time ./decompose $n int32_sort_symbolic < $tmp/minmax

    echo '
#include <stdio.h>
#include "int32_sort.h"
int main()
{
  printf("verified '$n' %s %s %s %s\\n",int32_sort_implementation,int32_sort_version,int32_sort_compiler,__VERSION__);
  return 0;
}
' > $tmp/verified.c

    time $c \
    -L $lib -Wl,-rpath=$lib \
    -I $lib/include \
    -o $tmp/verified $tmp/verified.c \
    -l djbsort

    ( tput bold >&2 || :; /bin/echo '')
    $tmp/verified
    ( tput sgr0 >&2 || :; /bin/echo '')
  
  done
done
