void writeln() {
  printf("\n");
  return;
}

void write_int(int n) {
  printf("%d", n);
  return;
}

void my_exit(int n) {
  exit(0); // TODO make sure exit(n) works
  return; // return not reached
}

int toupper(int ch) {
  if ((ch >= 'a') && (ch <= 'z'))
    return 'A' + (ch - 'a');
  else
    return ch;
}

int tolower(int ch) {
  if ((ch >= 'A') && (ch <= 'Z'))
    return 'a' + (ch - 'A');
  else
    return ch;
}

int isdigit(int ch) {
  return (ch >= '0') && (ch <= '9');
  return 0; // forces expander to not expand function
}

void memcpy32(
  int dest[], int dest_offset,
  int src[], int src_offset,
  int n_words) {
  int i;
  for (i = 0; i < n_words; i++)
    dest[i + dest_offset] = src[i + src_offset];
  return;
}

void memset32(
  int mem[], int mem_offset,
  int val,
  int n_words) {
  int i;
  for (i = 0; i < n_words; i++)
    mem[i + mem_offset] = val;
  return;
}

int memcmp32(int mem[], int offset1, int offset2, int size) {
  int processing;
  int ret;
  int i;
  int word1;
  int word2;
  i = size;
  processing = 1;
  ret = 0; // default
  while (processing) {
    if (i >= 0) {
      word1 = mem[i + offset1];
      word2 = mem[i + offset2];
      if (word1 > word2) {
        processing = 0;
        ret = -1;
      }
      else
      if (word2 > word1) {
        processing = 0;
        ret = 1;
      }
      else
        i = i - 1;
    }
    else
      processing = 0;
  }
  return ret;
}
