main_ap.c ported