int _atoi(int token) {
  // only handles positive numbers. this compiler prefaces negative
  // numbers with a unary minus
  int end_char_idx;
  int i;
  int ch;
  int token_size;
  int int_val;
  int power;
  token_size = string_pool[token];
  end_char_idx = 0;
  power = 1;
  int_val = 0;
  for (i = token_size - 1; i >= end_char_idx; i--) {
    ch = string_pool[token + i + 1];
    int_val = int_val + (ch - '0') * power;
    power = power * 10;
  }
  return int_val;
}

int htoi(int token) {
  int end_char_idx;
  int i;
  int ch;
  int token_size;
  int int_val;
  token_size = string_pool[token];
  if (token_size > 9)
    // 8 or more hex digits
    log_error(BAD_HEX_NUMBER, token);
  end_char_idx = 1;
  // exclude $ character
  int_val = 0;
  for (i = end_char_idx; i <= token_size - 1; i++) {
    ch = string_pool[token + i + 1];
    if (ch >= 'a')
      int_val = (int_val << 4) | ((ch - 'a') + 10);
    else
      int_val = (int_val << 4) | (ch - '0');
  }
  return int_val;
}

int itoa_char_token(int n) {
  int n_temp;
  int token;
  int string_size;
  int string_idx;
  int first_idx;
  string_size = 0;
  n_temp = n;
  do {
    string_size = string_size + 1;
    n_temp = n_temp / 10;
  } while (!(n_temp == 0));
  token = pool_idx;
  string_pool[pool_idx] = string_size;
  first_idx = 0;
  for (string_idx = string_size; string_idx > first_idx; string_idx--) {
    string_pool[pool_idx + string_idx] = n % 10 + '0';
    n = n / 10;
  }
  pool_idx = pool_idx + string_size + 1;
  string_pool[pool_idx] = 0;
  pool_idx = pool_idx + 1;
  return intern(token);
}
