typedef int size_t;
extern	struct	_iobuf {
int	_cnt;
unsigned char *_ptr;
unsigned char *_base;
int	_bufsiz;
short	_flag;
char	_file;	} _iob[];
typedef struct _iobuf FILE;
extern struct _iobuf	*fopen(const char *, const char *);
extern struct _iobuf	*fdopen(int, const char *);
extern struct _iobuf	*freopen(const char *, const char *, FILE *);
extern struct _iobuf	*popen(const char *, const char *);
extern struct _iobuf	*tmpfile(void);
extern long	ftell(FILE *);
extern char	*fgets(char *, int, FILE *);
extern char	*gets(char *);
extern char	*sprintf(char *, const char *, ...);
extern char	*ctermid(char *);
extern char	*cuserid(char *);
extern char	*tempnam(const char *, const char *);
extern char	*tmpnam(char *);
typedef struct sm_element_struct sm_element;
typedef struct sm_row_struct sm_row;
typedef struct sm_col_struct sm_col;
typedef struct sm_matrix_struct sm_matrix;
struct sm_element_struct {
int row_num;	int col_num;	sm_element *next_row;	sm_element *prev_row;	sm_element *next_col;	sm_element *prev_col;	char *user_word;	};
struct sm_row_struct {
int row_num;	int length;	int flag;	sm_element *first_col;	sm_element *last_col;	sm_row *next_row;	sm_row *prev_row;	char *user_word;	};
struct sm_col_struct {
int col_num;	int length;	int flag;	sm_element *first_row;	sm_element *last_row;	sm_col *next_col;	sm_col *prev_col;	char *user_word;	};
struct sm_matrix_struct {
sm_row **rows;	int rows_size;	sm_col **cols;	int cols_size;	sm_row *first_row;	sm_row *last_row;	int nrows;	sm_col *first_col;	sm_col *last_col;	int ncols;	char *user_word;	};
extern sm_matrix *sm_alloc(), *sm_alloc_size(), *sm_dup();
extern void sm_free(), sm_delrow(), sm_delcol(), sm_resize();
extern void sm_write(), sm_print(), sm_dump(), sm_cleanup();
extern void sm_copy_row(), sm_copy_col();
extern void sm_remove(), sm_remove_element();
extern sm_element *sm_insert(), *sm_find();
extern sm_row *sm_longest_row();
extern sm_col *sm_longest_col();
extern int sm_read(), sm_read_compressed();
extern sm_row *sm_row_alloc(), *sm_row_dup(), *sm_row_and();
extern void sm_row_free(), sm_row_remove(), sm_row_print();
extern sm_element *sm_row_insert(), *sm_row_find();
extern int sm_row_contains(), sm_row_intersects();
extern int sm_row_compare(), sm_row_hash();
extern sm_col *sm_col_alloc(), *sm_col_dup(), *sm_col_and();
extern void sm_col_free(), sm_col_remove(), sm_col_print();
extern sm_element *sm_col_insert(), *sm_col_find();
extern int sm_col_contains(), sm_col_intersects();
extern int sm_col_compare(), sm_col_hash();
extern int sm_row_dominance(), sm_col_dominance(), sm_block_partition();
extern sm_row *sm_minimum_cover();
extern	char	_ctype_[];
extern struct _iobuf *popen(const char *, const char *), *tmpfile(void);
extern int pclose(FILE *);
extern void rewind(FILE *);
extern void abort(void), free(void *), exit(int), perror(const char *);
extern char *getenv(const char *), *malloc(size_t), *realloc(void *, size_t);
extern int system(const char *);
extern double atof(const char *);
extern char *strcpy(char *, const char *), *strncpy(char *, const char *, size_t), *strcat(char *, const char *), *strncat(char *, const char *, size_t), *strerror(int);
extern char *strpbrk(const char *, const char *), *strtok(char *, const char *), *strchr(const char *, int), *strrchr(const char *, int), *strstr(const char *, const char *);
extern int strcoll(const char *, const char *), strxfrm(char *, const char *, size_t), strncmp(const char *, const char *, size_t), strlen(const char *), strspn(const char *, const char *), strcspn(const char *, const char *);
extern char *memmove(void *, const void *, size_t), *memccpy(void *, const void *, int, size_t), *memchr(const void *, int, size_t), *memcpy(void *, const void *, size_t), *memset(void *, int, size_t);
extern int memcmp(const void *, const void *, size_t), strcmp(const char *, const char *);
extern long util_cpu_time();
extern int util_getopt();
extern void util_getopt_reset();
extern char *util_path_search();
extern char *util_file_search();
extern int util_pipefork();
extern void util_print_cpu_stats();
extern char *util_print_time();
extern int util_save_image();
extern char *util_strsav();
extern char *util_tilde_expand();
extern void util_restart();
extern int util_optind;
extern char *util_optarg;

typedef unsigned int *pset;
typedef struct set_family {
int wsize; int sf_size; int capacity; int count; int active_count; pset data; struct set_family *next; } set_family_t, *pset_family;
extern int bit_count[256];

typedef struct cost_struct {
int cubes;	int in;	int out;	int mv;	int total;	int primes;	} cost_t, *pcost;
typedef struct pair_struct {
int cnt;
int *var1;
int *var2;
} pair_t, *ppair;
typedef struct symbolic_list_struct {
int variable;
int pos;
struct symbolic_list_struct *next;
} symbolic_list_t;
typedef struct symbolic_label_struct {
char *label;
struct symbolic_label_struct *next;
} symbolic_label_t;
typedef struct symbolic_struct {
symbolic_list_t *symbolic_list;	int symbolic_list_length;	symbolic_label_t *symbolic_label;	int symbolic_label_length;	struct symbolic_struct *next;
} symbolic_t;
typedef struct {
pset_family F, D, R;	char *filename; int pla_type; pset phase; ppair pair; char **label;	symbolic_t *symbolic;	symbolic_t *symbolic_output;
} PLA_t, *pPLA;

extern unsigned int debug; extern int verbose_debug; extern char *total_name[16]; extern long total_time[16]; extern int total_calls[16]; extern int echo_comments;	extern int echo_unknown_commands;	extern int force_irredundant; extern int skip_make_sparse;
extern int kiss; extern int pos; extern int print_solution; extern int recompute_onset; extern int remove_essential; extern int single_expand; extern int summary; extern int trace; extern int unwrap_onset; extern int use_random_order;	extern int use_super_gasp;	extern char *filename;	extern int debug_exact_minimization; struct pla_types_struct {
char *key;
int value;
};
struct cube_struct {
int size; int num_vars; int num_binary_vars; int *first_part; int *last_part; int *part_size; int *first_word; int *last_word; pset binary_mask; pset mv_mask; pset *var_mask; pset *temp; pset fullset; pset emptyset; unsigned int inmask; int inword; int *sparse; int num_mv_vars; int output; };
struct cdata_struct {
int *part_zeros; int *var_zeros; int *parts_active; int *is_unate; int vars_active; int vars_unate; int best; };
extern struct pla_types_struct pla_types[];
extern struct cube_struct cube, temp_cube_save;
extern struct cdata_struct cdata, temp_cdata_save;

extern int binate_split_select();
extern pset_family cubeunlist();
extern pset *cofactor();
extern pset *cube1list();
extern pset *cube2list();
extern pset *cube3list();
extern pset *scofactor();
extern void massive_count();
extern pset_family complement();
extern pset_family simplify();
extern void simp_comp();
extern int d1_rm_equal(register pset *A1, int (*compare) ());
extern int rm2_contain(pset *A1, pset *B1);
extern int rm2_equal(register pset *A1, register pset *B1, pset *E1, int (*compare) ());
extern int rm_contain(pset *A1);
extern int rm_equal(pset *A1, int (*compare) ());
extern int rm_rev_contain(pset *A1);
extern pset *sf_list(register pset_family A);
extern pset *sf_sort(pset_family A, int (*compare) ());
extern pset_family d1merge(pset_family A, int var);
extern pset_family dist_merge(pset_family A, pset mask);
extern pset_family sf_contain(pset_family A);
extern pset_family sf_dupl(pset_family A);
extern pset_family sf_ind_contain(pset_family A, int *row_indices);
extern pset_family sf_ind_unlist(pset *A1, int totcnt, int size, int *row_indices, register pset pfirst);
extern pset_family sf_merge(pset *A1, pset *B1, pset *E1, int totcnt, int size);
extern pset_family sf_rev_contain(pset_family A);
extern pset_family sf_union(pset_family A, pset_family B);
extern pset_family sf_unlist(pset *A1, int totcnt, int size);
extern void cube_setup();
extern void restore_cube_struct();
extern void save_cube_struct();
extern void setdown_cube();
extern PLA_labels();
extern char *get_word();
extern int label_index();
extern int read_pla();
extern int read_symbolic();
extern pPLA new_PLA();
extern void PLA_summary();
extern void free_PLA();
extern void parse_pla();
extern void read_cube();
extern void skip_line();
extern foreach_output_function();
extern int cubelist_partition();
extern int so_both_do_espresso();
extern int so_both_do_exact();
extern int so_both_save();
extern int so_do_espresso();
extern int so_do_exact();
extern int so_save();
extern pset_family cof_output();
extern pset_family lex_sort();
extern pset_family mini_sort();
extern pset_family random_order();
extern pset_family size_sort();
extern pset_family sort_reduce();
extern pset_family uncof_output();
extern pset_family unravel();
extern pset_family unravel_range();
extern void so_both_espresso();
extern void so_espresso();
extern char *fmt_cost();
extern char *print_cost();
extern char *util_strsav();
extern void copy_cost();
extern void cover_cost();
extern void fatal();
extern void print_trace();
extern void size_stamp();
extern void totals();
extern char *fmt_cube();
extern char *fmt_expanded_cube();
extern char *pc1();
extern char *pc2();
extern char *pc3();
extern int makeup_labels();
extern kiss_output();
extern kiss_print_cube();
extern output_symbolic_constraints();
extern void cprint();
extern void debug1_print();
extern void debug_print();
extern void eqn_output();
extern void fpr_header();
extern void fprint_pla();
extern void pls_group();
extern void pls_label();
extern void pls_output();
extern void print_cube();
extern void print_expanded_cube();
extern void sf_debug_print();
extern find_equiv_outputs();
extern int check_equiv();
extern pset_family espresso();
extern int essen_cube();
extern pset_family cb_consensus();
extern pset_family cb_consensus_dist0();
extern pset_family essential();
extern pset_family minimize_exact();
extern pset_family minimize_exact_literals();
extern int feasibly_covered();
extern int most_frequent();
extern pset_family all_primes();
extern pset_family expand();
extern pset_family find_all_primes();
extern void elim_lowering();
extern void essen_parts();
extern void essen_raising();
extern void expand1();
extern void mincov();
extern void select_feasible();
extern void setup_BB_CC();
extern pset_family expand_gasp();
extern pset_family irred_gasp();
extern pset_family last_gasp();
extern pset_family super_gasp();
extern void expand1_gasp();
extern int util_getopt();
extern find_dc_inputs();
extern find_inputs();
extern form_bitvector();
extern map_dcset();
extern map_output_symbolic();
extern map_symbolic();
extern pset_family map_symbolic_cover();
extern symbolic_hack_labels();
extern int cube_is_covered();
extern int taut_special_cases();
extern int tautology();
extern pset_family irredundant();
extern void mark_irredundant();
extern void irred_split_cover();
extern sm_matrix *irred_derive_table();
extern pset minterms();
extern void explode();
extern void map();
extern output_phase_setup();
extern pPLA set_phase();
extern pset_family opo();
extern pset find_phase();
extern pset_family find_covers();
extern pset_family form_cover_table();
extern pset_family opo_leaf();
extern pset_family opo_recur();
extern void opoall();
extern void phase_assignment();
extern void repeated_phase_assignment();
extern generate_all_pairs();
extern int **find_pairing_cost();
extern int find_best_cost();
extern int greedy_best_cost();
extern int minimize_pair();
extern int pair_free();
extern pair_all();
extern pset_family delvar();
extern pset_family pairvar();
extern ppair pair_best_cost();
extern ppair pair_new();
extern ppair pair_save();
extern print_pair();
extern void find_optimal_pairing();
extern void set_pair();
extern void set_pair1();
extern pset_family primes_consensus();
extern int sccc_special_cases();
extern pset_family reduce();
extern pset reduce_cube();
extern pset sccc();
extern pset sccc_cube();
extern pset sccc_merge();
extern int set_andp();
extern int set_orp();
extern int setp_disjoint();
extern int setp_empty();
extern int setp_equal();
extern int setp_full();
extern int setp_implies();
extern char *pbv1();
extern char *ps1();
extern int *sf_count();
extern int *sf_count_restricted();
extern int bit_index();
extern int set_dist();
extern int set_ord();
extern void set_adjcnt();
extern pset set_and();
extern pset set_clear();
extern pset set_copy();
extern pset set_diff();
extern pset set_fill();
extern pset set_merge();
extern pset set_or();
extern pset set_xor();
extern pset sf_and();
extern pset sf_or();
extern pset_family sf_active();
extern pset_family sf_addcol();
extern pset_family sf_addset();
extern pset_family sf_append();
extern pset_family sf_bm_read();
extern pset_family sf_compress();
extern pset_family sf_copy();
extern pset_family sf_copy_col();
extern pset_family sf_delc();
extern pset_family sf_delcol();
extern pset_family sf_inactive();
extern pset_family sf_join();
extern pset_family sf_new();
extern pset_family sf_permute();
extern pset_family sf_read();
extern pset_family sf_save();
extern pset_family sf_transpose();
extern void set_write();
extern void sf_bm_print();
extern void sf_cleanup();
extern void sf_delset();
extern void sf_free();
extern void sf_print();
extern void sf_write();
extern int ccommon();
extern int cdist0();
extern int full_row();
extern int ascend();
extern int cactive();
extern int cdist();
extern int cdist01();
extern int cvolume();
extern int d1_order();
extern int d1_order_size();
extern int desc1();
extern int descend();
extern int lex_order();
extern int lex_order1();
extern pset force_lower();
extern void consensus();
extern pset_family cb1_dsharp();
extern pset_family cb_dsharp();
extern pset_family cb_recur_dsharp();
extern pset_family cb_recur_sharp();
extern pset_family cb_sharp();
extern pset_family cv_dsharp();
extern pset_family cv_intersect();
extern pset_family cv_sharp();
extern pset_family dsharp();
extern pset_family make_disjoint();
extern pset_family sharp();
pset do_sm_minimum_cover();
extern pset_family make_sparse();
extern pset_family mv_reduce();
extern qsort(void *, size_t, size_t, int (*) (const void *, const void *));
extern qst();
extern pset_family find_all_minimal_covers_petrick();
extern pset_family map_cover_to_unate();
extern pset_family map_unate_to_cover();
extern pset_family exact_minimum_cover();
extern pset_family gen_primes();
extern pset_family unate_compl();
extern pset_family unate_complement();
extern pset_family unate_intersect();
extern PLA_permute();
extern int PLA_verify();
extern int check_consistency();
extern int verify();
pset_family sf_contain(pset_family A)
{
int cnt;
pset *A1;
pset_family R;
A1 = sf_sort(A, descend); cnt = rm_equal(A1, descend); cnt = rm_contain(A1); R = sf_unlist(A1, cnt, A->sf_size); sf_free(A);
return R;
}
pset_family sf_rev_contain(pset_family A)
{
int cnt;
pset *A1;
pset_family R;
A1 = sf_sort(A, ascend); cnt = rm_equal(A1, ascend); cnt = rm_rev_contain(A1); R = sf_unlist(A1, cnt, A->sf_size); sf_free(A);
return R;
}
pset_family sf_ind_contain(pset_family A, int *row_indices)
{
int cnt;
pset *A1;
pset_family R;
A1 = sf_sort(A, descend); cnt = rm_equal(A1, descend); cnt = rm_contain(A1); R = sf_ind_unlist(A1, cnt, A->sf_size, row_indices, A->data);
sf_free(A);
return R;
}
pset_family sf_dupl(pset_family A)
{
register int cnt;
register pset *A1;
pset_family R;
A1 = sf_sort(A, descend); cnt = rm_equal(A1, descend); R = sf_unlist(A1, cnt, A->sf_size); sf_free(A);
return R;
}
pset_family sf_union(pset_family A, pset_family B)
{
int cnt;
pset_family R;
pset *A1 = sf_list(A), *B1 = sf_list(B), *E1;
E1 = ((pset *) malloc(sizeof(pset) * ( ((A->count) > ( B->count) ? (A->count) : ( B->count)) + 1)));
cnt = rm2_equal(A1, B1, E1, descend);
cnt += rm2_contain(A1, B1) + rm2_contain(B1, A1);
R = sf_merge(A1, B1, E1, cnt, A->sf_size);
sf_free(A); sf_free(B);
return R;
}
pset_family dist_merge(pset_family A, pset mask)
{
pset *A1;
int cnt;
pset_family R;
set_copy(cube.temp[0], mask);
A1 = sf_sort(A, d1_order);
cnt = d1_rm_equal(A1, d1_order);
R = sf_unlist(A1, cnt, A->sf_size);
sf_free(A);
return R;
}
pset_family d1merge(pset_family A, int var)
{
return dist_merge(A, cube.var_mask[var]);
}
int d1_rm_equal(register pset *A1, int (*compare) ())
{
register int i, j, dest;
dest = 0;
if (A1[0] != (pset) 0) {
for(i = 0, j = 1; A1[j] != (pset) 0; j++)
if ( (*compare)(&A1[i], &A1[j]) == 0) {
set_or(A1[i], A1[i], A1[j]);
} else {
A1[dest++] = A1[i];
i = j;
}
A1[dest++] = A1[i];
}
A1[dest] = (pset) 0;
return dest;
}
int rm_equal(pset *A1, int (*compare) ())
{
register pset *p, *pdest = A1;
if (*A1 != 0) { for(p = A1+1; *p != 0; p++)
if ((*compare)(p, p-1) != 0)
*pdest++ = *(p-1);
*pdest++ = *(p-1);
*pdest = 0;
}
return pdest - A1;
}
int rm_contain(pset *A1)
{
register pset *pa, *pb, *pcheck, a, b;
pset *pdest = A1;
int last_size = -1;
for(pa = A1; (a = *pa++) != 0; ) {
if ((a[0] >> 16) != last_size)
last_size = (a[0] >> 16), pcheck = pdest;
for(pb = A1; pb != pcheck; ) {
b = *pb++;
{register int i_=(a[0] & 0x03ff); do if (a[i_]&~ b[i_]) break; while (--i_>0); if (i_ != 0) continue;};
goto lnext1;
}
*pdest++ = a;
lnext1: ;
}
*pdest = 0;
return pdest - A1;
}
int rm_rev_contain(pset *A1)
{
register pset *pa, *pb, *pcheck, a, b;
pset *pdest = A1;
int last_size = -1;
for(pa = A1; (a = *pa++) != 0; ) {
if ((a[0] >> 16) != last_size)
last_size = (a[0] >> 16), pcheck = pdest;
for(pb = A1; pb != pcheck; ) {
b = *pb++;
{register int i_=(b[0] & 0x03ff); do if (b[i_]&~ a[i_]) break; while (--i_>0); if (i_ != 0) continue;};
goto lnext1;
}
*pdest++ = a;
lnext1: ;
}
*pdest = 0;
return pdest - A1;
}
int rm2_equal(register pset *A1, register pset *B1, pset *E1, int (*compare) ())
{
register pset *pda = A1, *pdb = B1, *pde = E1;
for(; *A1 != 0 && *B1 != 0; )
switch((*compare)(A1, B1)) {
case -1: *pda++ = *A1++; break;
case 0: *pde++ = *A1++; B1++; break;
case 1: *pdb++ = *B1++; break;
}
while (*A1 != 0)
*pda++ = *A1++;
while (*B1 != 0)
*pdb++ = *B1++;
*pda = *pdb = *pde = 0;
return pde - E1;
}
int rm2_contain(pset *A1, pset *B1)
{
register pset *pa, *pb, a, b, *pdest = A1;
for(pa = A1; (a = *pa++) != 0; ) {
for(pb = B1; (b = *pb++) != 0 && (b[0] >> 16) > (a[0] >> 16); ) {
{register int i_=(a[0] & 0x03ff); do if (a[i_]&~ b[i_]) break; while (--i_>0); if (i_ != 0) continue;};
goto lnext1;
}
*pdest++ = a;
lnext1: ;
}
*pdest = 0; return pdest - A1; }
pset *sf_sort(pset_family A, int (*compare) ())
{
register pset p, last, *pdest, *A1;
pdest = A1 = ((pset *) malloc(sizeof(pset) * ( A->count + 1)));
for( p=A->data, last= p+A->count*A->wsize; p< last; p+=A->wsize) {
(p[0] &= 0xffff, p[0] |= (( set_ord(p)) << 16)); *pdest++ = p; }
*pdest = 0; qsort((char *) A1, A->count, sizeof(pset), compare);
return A1;
}
pset *sf_list(register pset_family A)
{
register pset p, last, *pdest, *A1;
pdest = A1 = ((pset *) malloc(sizeof(pset) * ( A->count + 1)));
for( p=A->data, last= p+A->count*A->wsize; p< last; p+=A->wsize)
*pdest++ = p; *pdest = 0; return A1;
}
pset_family sf_unlist(pset *A1, int totcnt, int size)
{
register pset pr, p, *pa;
pset_family R = sf_new(totcnt, size);
R->count = totcnt;
for(pr = R->data, pa = A1; (p = *pa++) != 0; pr += R->wsize)
{register int i_=( p[0] & 0x03ff); do pr[i_]= p[i_]; while (--i_>=0);};
((A1) ? (free((char *) (A1)), (A1) = 0) : 0);
return R;
}
pset_family sf_ind_unlist(pset *A1, int totcnt, int size, int *row_indices, register pset pfirst)
{
register pset pr, p, *pa;
register int i, *new_row_indices;
pset_family R = sf_new(totcnt, size);
R->count = totcnt;
new_row_indices = ((int *) malloc(sizeof(int) * ( totcnt)));
for(pr = R->data, pa = A1, i=0; (p = *pa++) != 0; pr += R->wsize, i++) {
{register int i_=( p[0] & 0x03ff); do pr[i_]= p[i_]; while (--i_>=0);};
new_row_indices[i] = row_indices[(p - pfirst)/R->wsize];
}
for(i = 0; i < totcnt; i++)
row_indices[i] = new_row_indices[i];
((new_row_indices) ? (free((char *) (new_row_indices)), (new_row_indices) = 0) : 0);
((A1) ? (free((char *) (A1)), (A1) = 0) : 0);
return R;
}
pset_family sf_merge(pset *A1, pset *B1, pset *E1, int totcnt, int size)
{
register pset pr, ps, *pmin, *pmid, *pmax;
pset_family R;
pset *temp[3], *swap;
int i, j, n;
R = sf_new(totcnt, size);
R->count = totcnt;
pr = R->data;
n = 3; temp[0] = A1; temp[1] = B1; temp[2] = E1;
for(i = 0; i < n-1; i++)
for(j = i+1; j < n; j++)
if (desc1(*temp[i], *temp[j]) > 0) {
swap = temp[j];
temp[j] = temp[i];
temp[i] = swap;
}
pmin = temp[0]; pmid = temp[1]; pmax = temp[2];
while (*pmin != (pset) 0) {
ps = *pmin++;
{register int i_=( ps[0] & 0x03ff); do pr[i_]= ps[i_]; while (--i_>=0);};
pr += R->wsize;
if (desc1(*pmin, *pmax) > 0) {
swap = pmax; pmax = pmin; pmin = pmid; pmid = swap;
} else if (desc1(*pmin, *pmid) > 0) {
swap = pmin; pmin = pmid; pmid = swap;
}
}
((A1) ? (free((char *) (A1)), (A1) = 0) : 0);
((B1) ? (free((char *) (B1)), (B1) = 0) : 0);
((E1) ? (free((char *) (E1)), (E1) = 0) : 0);
return R;
}
