def METHOD_NAME(decls, declared):
    """ Order the types by dependency. """
    decl, seen = set(), set()
    ordered = []
    todo = decls[:]
    seen.add('ALLEGRO_EVENT_TYPE')
    seen.add('ALLEGRO_KEY_MAX')
    seen.add('ALLEGRO_USER_EVENT_DESCRIPTOR')
    def info(t):
        brk, brk2 = t.find('{'), t.rfind('}')
        tbrk = t[brk+1:brk2] if brk >= 0 and brk2 >= 0 else None
        tw = t.split(' ')
        name = None
        if tw[0] in ('struct', 'union'):
            name = tw[1]
        elif tw[0] == 'typedef':
            if tw[1] in ('struct', 'union'):
                name = tw[2]
        return name, tbrk
    for t in declared:
        name, _ = info(t)
        if name:
            decl.add(name)
    reall = re.compile('(ALLEGRO_\w+\s*\*?)')
    retname = re.compile('(ALLEGRO_\w+)')
    c = 0
    while True:
        lb = len(todo)
        for t in todo[:]:
            name, brk = info(t)
            aldeps = reall.findall(brk)
            ok = True
            # print aldeps
            for rdep in aldeps:
                dep = retname.match(rdep).group(1)
                if dep.startswith('ALLEGRO_GL_'):
                    continue    # ignore
                if dep in decl and rdep[-1] == '*':
                    continue    # ok, seen type and ptr
                if not dep in seen:
                    ok = False
                    break
            if ok:
                ordered.append(t)
                todo.remove(t)
                seen.add(name)
        if len(todo) == 0:
            break
        elif lb == len(todo):
            c += 1
            assert c < 10, 'loop, bad'
    # ordered += todo
    return ordered