#include "../lib.h"

#define REPLICA_COUNT 1

static plain_t sum_out[REPLICA_COUNT];

#define X sum_out[0]

template <const unsigned int N> static INLINE void sum(void) {
  int sum = 0;
  for (int i = 0; i < 5; ++i) {
    sum += 1;
  }

  sum_out[N] = sum;
}

extern "C" EXPORT("wasm_module") int wasm_module(void) {
  X = 0;

  fail_start_trace();

  sum<0>();

  fail_stop_trace();

  if (X == 5) {
    PRINT("result correct.\n");
    fail_marker_positive();
    return 0;
  } else {
    PRINT("result incorrect.\n");
    fail_marker_negative();
    return 1;
  }
}
