#include <stdint.h>
#include <stdlib.h>
#include "el_runtime.h"

el_val_t str_ends(el_val_t s, el_val_t suf);
el_val_t str_last_char(el_val_t s);
el_val_t str_last2(el_val_t s);
el_val_t str_last3(el_val_t s);
el_val_t str_drop_last(el_val_t s, el_val_t n);
el_val_t is_vowel(el_val_t c);
el_val_t morph_apply_suffix(el_val_t base, el_val_t suffix);
el_val_t en_irregular_plural(el_val_t word);
el_val_t en_irregular_singular(el_val_t word);
el_val_t en_irregular_verb(el_val_t base);
el_val_t en_verb_3sg(el_val_t base);
el_val_t en_should_double_final(el_val_t base);
el_val_t en_verb_past(el_val_t base);
el_val_t en_verb_gerund(el_val_t base);
el_val_t en_pluralize_regular(el_val_t singular);
el_val_t en_verb_form(el_val_t base, el_val_t tense, el_val_t person, el_val_t number);
el_val_t agree_determiner(el_val_t det, el_val_t noun);
el_val_t morph_pluralize(el_val_t noun, el_val_t profile);
el_val_t morph_map_canonical(el_val_t verb, el_val_t code);
el_val_t morph_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number, el_val_t profile);
el_val_t morph_inflect(el_val_t word, el_val_t features, el_val_t profile);
el_val_t pluralize(el_val_t singular);
el_val_t singularize(el_val_t plural);
el_val_t verb_form(el_val_t base, el_val_t tense, el_val_t person, el_val_t number);
el_val_t irregular_plural(el_val_t word);
el_val_t irregular_singular(el_val_t word);
el_val_t peo_drop(el_val_t s, el_val_t n);
el_val_t peo_ends(el_val_t s, el_val_t suf);
el_val_t peo_slot(el_val_t person, el_val_t number);
el_val_t peo_present_suffix(el_val_t slot);
el_val_t peo_past_suffix(el_val_t slot);
el_val_t peo_ah_present(el_val_t slot);
el_val_t peo_ah_past(el_val_t slot);
el_val_t peo_kar_present(el_val_t slot);
el_val_t peo_kar_past(el_val_t slot);
el_val_t peo_xsaya_present(el_val_t slot);
el_val_t peo_tar_present(el_val_t slot);
el_val_t peo_da_present(el_val_t slot);
el_val_t peo_da_past(el_val_t slot);
el_val_t peo_map_canonical(el_val_t verb);
el_val_t peo_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number);
el_val_t peo_decline_astem(el_val_t noun, el_val_t gram_case, el_val_t number);
el_val_t peo_decline(el_val_t noun, el_val_t gram_case, el_val_t number);
el_val_t peo_noun_phrase(el_val_t noun, el_val_t gram_case, el_val_t number, el_val_t definite);

el_val_t peo_drop(el_val_t s, el_val_t n) {
  el_val_t len = str_len(s);
  if (n >= len) {
    return EL_STR("");
  }
  return str_slice(s, 0, (len - n));
  return 0;
}

el_val_t peo_ends(el_val_t s, el_val_t suf) {
  return str_ends_with(s, suf);
  return 0;
}

el_val_t peo_slot(el_val_t person, el_val_t number) {
  if (str_eq(person, EL_STR("first"))) {
    if (str_eq(number, EL_STR("singular"))) {
      return 0;
    }
    return 3;
  }
  if (str_eq(person, EL_STR("second"))) {
    if (str_eq(number, EL_STR("singular"))) {
      return 1;
    }
    return 4;
  }
  if (str_eq(number, EL_STR("singular"))) {
    return 2;
  }
  return 5;
  return 0;
}

el_val_t peo_present_suffix(el_val_t slot) {
  if (slot == 0) {
    return EL_STR("\xc4\x81miy");
  }
  if (slot == 1) {
    return EL_STR("ahiy");
  }
  if (slot == 2) {
    return EL_STR("atiy");
  }
  if (slot == 3) {
    return EL_STR("\xc4\x81mahy");
  }
  if (slot == 4) {
    return EL_STR("\xc4\x81t\xc4\x81");
  }
  return EL_STR("antiy");
  return 0;
}

el_val_t peo_past_suffix(el_val_t slot) {
  if (slot == 0) {
    return EL_STR("am");
  }
  if (slot == 1) {
    return EL_STR("\xc4\x81");
  }
  if (slot == 2) {
    return EL_STR("a");
  }
  if (slot == 3) {
    return EL_STR("\xc4\x81m\xc4\x81");
  }
  if (slot == 4) {
    return EL_STR("\xc4\x81t\xc4\x81");
  }
  return EL_STR("\xc4\x81");
  return 0;
}

el_val_t peo_ah_present(el_val_t slot) {
  if (slot == 0) {
    return EL_STR("amiy");
  }
  if (slot == 1) {
    return EL_STR("ahiy");
  }
  if (slot == 2) {
    return EL_STR("astiy");
  }
  if (slot == 3) {
    return EL_STR("amahy");
  }
  if (slot == 4) {
    return EL_STR("ast\xc4\x81");
  }
  return EL_STR("hatiy");
  return 0;
}

el_val_t peo_ah_past(el_val_t slot) {
  if (slot == 0) {
    return EL_STR("\xc4\x81ham");
  }
  if (slot == 1) {
    return EL_STR("\xc4\x81ha");
  }
  if (slot == 2) {
    return EL_STR("\xc4\x81ha");
  }
  if (slot == 3) {
    return EL_STR("\xc4\x81hama");
  }
  if (slot == 4) {
    return EL_STR("\xc4\x81hata");
  }
  return EL_STR("\xc4\x81han");
  return 0;
}

el_val_t peo_kar_present(el_val_t slot) {
  if (slot == 0) {
    return EL_STR("kun\xc4\x81miy");
  }
  if (slot == 1) {
    return EL_STR("kun\xc4\x81hiy");
  }
  if (slot == 2) {
    return EL_STR("kunautiy");
  }
  if (slot == 3) {
    return EL_STR("kun\xc4\x81mahy");
  }
  if (slot == 4) {
    return EL_STR("kun\xc4\x81t\xc4\x81");
  }
  return EL_STR("kunavantiy");
  return 0;
}

el_val_t peo_kar_past(el_val_t slot) {
  if (slot == 0) {
    return EL_STR("akunavam");
  }
  if (slot == 1) {
    return EL_STR("akunav\xc4\x81");
  }
  if (slot == 2) {
    return EL_STR("akunava");
  }
  if (slot == 3) {
    return EL_STR("akunav\xc4\x81m\xc4\x81");
  }
  if (slot == 4) {
    return EL_STR("akunav\xc4\x81t\xc4\x81");
  }
  return EL_STR("akunavan");
  return 0;
}

el_val_t peo_xsaya_present(el_val_t slot) {
  if (slot == 0) {
    return EL_STR("x\xc5\xa1\xc4\x81y\xc4\x81miy");
  }
  if (slot == 1) {
    return EL_STR("x\xc5\xa1\xc4\x81y\xc4\x81hiy");
  }
  if (slot == 2) {
    return EL_STR("x\xc5\xa1\xc4\x81yatiy");
  }
  if (slot == 3) {
    return EL_STR("x\xc5\xa1\xc4\x81y\xc4\x81mahy");
  }
  if (slot == 4) {
    return EL_STR("x\xc5\xa1\xc4\x81y\xc4\x81t\xc4\x81");
  }
  return EL_STR("x\xc5\xa1\xc4\x81yantiy");
  return 0;
}

el_val_t peo_tar_present(el_val_t slot) {
  if (slot == 2) {
    return EL_STR("taratiy");
  }
  if (slot == 5) {
    return EL_STR("tarantiy");
  }
  return el_str_concat(EL_STR("tar"), peo_present_suffix(slot));
  return 0;
}

el_val_t peo_da_present(el_val_t slot) {
  if (slot == 0) {
    return EL_STR("d\xc4\x81miy");
  }
  if (slot == 1) {
    return EL_STR("d\xc4\x81hiy");
  }
  if (slot == 2) {
    return EL_STR("d\xc4\x81tiy");
  }
  if (slot == 3) {
    return EL_STR("d\xc4\x81mahy");
  }
  if (slot == 4) {
    return EL_STR("d\xc4\x81t\xc4\x81");
  }
  return EL_STR("dantiy");
  return 0;
}

el_val_t peo_da_past(el_val_t slot) {
  if (slot == 0) {
    return EL_STR("ad\xc4\x81m");
  }
  if (slot == 1) {
    return EL_STR("ad\xc4\x81\xc4\x81");
  }
  if (slot == 2) {
    return EL_STR("ad\xc4\x81");
  }
  if (slot == 3) {
    return EL_STR("ad\xc4\x81m\xc4\x81");
  }
  if (slot == 4) {
    return EL_STR("ad\xc4\x81t\xc4\x81");
  }
  return EL_STR("ad\xc4\x81n");
  return 0;
}

el_val_t peo_map_canonical(el_val_t verb) {
  if (str_eq(verb, EL_STR("be"))) {
    return EL_STR("ah");
  }
  if (str_eq(verb, EL_STR("do"))) {
    return EL_STR("kar");
  }
  if (str_eq(verb, EL_STR("make"))) {
    return EL_STR("kar");
  }
  if (str_eq(verb, EL_STR("rule"))) {
    return EL_STR("x\xc5\xa1\xc4\x81ya");
  }
  if (str_eq(verb, EL_STR("cross"))) {
    return EL_STR("tar");
  }
  if (str_eq(verb, EL_STR("give"))) {
    return EL_STR("d\xc4\x81");
  }
  return verb;
  return 0;
}

el_val_t peo_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number) {
  el_val_t v = peo_map_canonical(verb);
  el_val_t slot = peo_slot(person, number);
  if (str_eq(v, EL_STR("ah"))) {
    if (str_eq(tense, EL_STR("present"))) {
      return peo_ah_present(slot);
    }
    if (str_eq(tense, EL_STR("past"))) {
      return peo_ah_past(slot);
    }
    return v;
  }
  if (str_eq(v, EL_STR("kar"))) {
    if (str_eq(tense, EL_STR("present"))) {
      return peo_kar_present(slot);
    }
    if (str_eq(tense, EL_STR("past"))) {
      return peo_kar_past(slot);
    }
    return v;
  }
  if (str_eq(v, EL_STR("x\xc5\xa1\xc4\x81ya"))) {
    if (str_eq(tense, EL_STR("present"))) {
      return peo_xsaya_present(slot);
    }
    if (str_eq(tense, EL_STR("past"))) {
      return el_str_concat(EL_STR("x\xc5\xa1\xc4\x81ya"), peo_past_suffix(slot));
    }
    return v;
  }
  if (str_eq(v, EL_STR("tar"))) {
    if (str_eq(tense, EL_STR("present"))) {
      return peo_tar_present(slot);
    }
    if (str_eq(tense, EL_STR("past"))) {
      return el_str_concat(EL_STR("tar"), peo_past_suffix(slot));
    }
    return v;
  }
  if (str_eq(v, EL_STR("d\xc4\x81"))) {
    if (str_eq(tense, EL_STR("present"))) {
      return peo_da_present(slot);
    }
    if (str_eq(tense, EL_STR("past"))) {
      return peo_da_past(slot);
    }
    return v;
  }
  if (str_eq(tense, EL_STR("present"))) {
    return el_str_concat(v, peo_present_suffix(slot));
  }
  if (str_eq(tense, EL_STR("past"))) {
    return el_str_concat(v, peo_past_suffix(slot));
  }
  return v;
  return 0;
}

el_val_t peo_decline_astem(el_val_t noun, el_val_t gram_case, el_val_t number) {
  if (str_eq(noun, EL_STR("dahyu"))) {
    if (str_eq(number, EL_STR("singular"))) {
      if (str_eq(gram_case, EL_STR("nominative"))) {
        return EL_STR("dahy\xc4\x81u\xc5\xa1");
      }
      if (str_eq(gram_case, EL_STR("accusative"))) {
        return EL_STR("dahyum");
      }
      if (str_eq(gram_case, EL_STR("genitive"))) {
        return EL_STR("dahy\xc4\x81u\xc5\xa1");
      }
      if (str_eq(gram_case, EL_STR("dative"))) {
        return EL_STR("dahyav\xc4\x81");
      }
      return EL_STR("dahy\xc4\x81u\xc5\xa1");
    }
    if (str_eq(gram_case, EL_STR("nominative"))) {
      return EL_STR("dahy\xc4\x81va");
    }
    if (str_eq(gram_case, EL_STR("accusative"))) {
      return EL_STR("dahy\xc5\xabn");
    }
    if (str_eq(gram_case, EL_STR("genitive"))) {
      return EL_STR("dahy\xc5\xabn\xc4\x81m");
    }
    if (str_eq(gram_case, EL_STR("dative"))) {
      return EL_STR("dahyubiy\xc4\x81");
    }
    return EL_STR("dahy\xc4\x81va");
  }
  if (str_eq(number, EL_STR("singular"))) {
    if (str_eq(gram_case, EL_STR("nominative"))) {
      return el_str_concat(noun, EL_STR("\xc4\x81u\xc5\xa1"));
    }
    if (str_eq(gram_case, EL_STR("accusative"))) {
      return el_str_concat(noun, EL_STR("am"));
    }
    if (str_eq(gram_case, EL_STR("genitive"))) {
      return el_str_concat(noun, EL_STR("\xc4\x81u\xc5\xa1"));
    }
    if (str_eq(gram_case, EL_STR("dative"))) {
      return el_str_concat(noun, EL_STR("av\xc4\x81"));
    }
    return el_str_concat(noun, EL_STR("\xc4\x81u\xc5\xa1"));
  }
  if (str_eq(gram_case, EL_STR("nominative"))) {
    return el_str_concat(noun, EL_STR("\xc4\x81va"));
  }
  if (str_eq(gram_case, EL_STR("accusative"))) {
    return el_str_concat(noun, EL_STR("\xc5\xabn"));
  }
  if (str_eq(gram_case, EL_STR("genitive"))) {
    return el_str_concat(noun, EL_STR("\xc5\xabn\xc4\x81m"));
  }
  if (str_eq(gram_case, EL_STR("dative"))) {
    return el_str_concat(noun, EL_STR("ubiy\xc4\x81"));
  }
  return el_str_concat(noun, EL_STR("\xc4\x81va"));
  return 0;
}

el_val_t peo_decline(el_val_t noun, el_val_t gram_case, el_val_t number) {
  return peo_decline_astem(noun, gram_case, number);
  return 0;
}

el_val_t peo_noun_phrase(el_val_t noun, el_val_t gram_case, el_val_t number, el_val_t definite) {
  return peo_decline(noun, gram_case, number);
  return 0;
}

