g_ai.c

from Q2 original source