#ifndef _terminate_h_INCLUDED
#define _terminate_h_INCLUDED

#include "internal.h"

#ifndef QUIET
void kissat_report_termination (kissat *, const char *name,
                                const char *file, long lineno,
                                const char *fun);
#endif

static inline bool kissat_terminated (kissat *solver, int bit,
                                      const char *name, const char *file,
                                      long lineno, const char *fun) {
  assert (0 <= bit), assert (bit < 64);
#ifdef COVERAGE
  const uint64_t mask = (uint64_t) 1 << bit;
  if (!(solver->termination.flagged & mask))
    return false;
  solver->termination.flagged = ~(uint64_t) 0;
#else
  if (!solver->termination.flagged)
    return false;
#endif
#ifndef QUIET
  kissat_report_termination (solver, name, file, lineno, fun);
#else
  (void) file;
  (void) fun;
  (void) lineno;
  (void) name;
#endif
#if !defined(COVERAGE) && defined(NDEBUG)
  (void) bit;
#endif
  return true;
}

#define TERMINATED(BIT) \
  kissat_terminated (solver, BIT, #BIT, __FILE__, __LINE__, __func__)

#define backbone_terminated_1 1
#define backbone_terminated_2 2
#define backbone_terminated_3 3
#define congruence_terminated_1 4
#define congruence_terminated_2 5
#define congruence_terminated_3 6
#define congruence_terminated_4 7
#define congruence_terminated_5 8
#define congruence_terminated_6 9
#define congruence_terminated_7 10
#define congruence_terminated_8 11
#define congruence_terminated_9 12
#define congruence_terminated_10 13
#define congruence_terminated_11 14
#define congruence_terminated_12 15
#define eliminate_terminated_1 16
#define eliminate_terminated_2 17
#define factor_terminated_1 18
#define forward_terminated_1 19
#define kitten_terminated_1 20
#define preprocess_terminated_1 21
#define search_terminated_1 22
#define substitute_terminated_1 23
#define sweep_terminated_1 24
#define sweep_terminated_2 25
#define sweep_terminated_3 26
#define sweep_terminated_4 27
#define sweep_terminated_5 28
#define sweep_terminated_6 29
#define sweep_terminated_7 30
#define sweep_terminated_8 31
#define transitive_terminated_1 32
#define transitive_terminated_2 33
#define transitive_terminated_3 34
#define vivify_terminated_1 35
#define vivify_terminated_2 36
#define vivify_terminated_3 37
#define vivify_terminated_4 38
#define walk_terminated_1 39
#define warmup_terminated_1 40

#endif
