When you encounter still mim, decide the rule using the next pronounced letter. In these rules, word meaning, the vowel before mim, and whether mim lies at a word boundary are not the main determining factors.
«لَهُمْ مَّا» — followed by mim: idgham shafawi, with ghunnah.
«هُمْ بِهِ» — followed by ba: ikhfa shafawi, with ghunnah.
«أَنْعَمْتَ» — followed by ta: izhar shafawi.
«هُمْ فِيهَا» — followed by fa: still izhar shafawi.
If mim and ba are articulated as two separated, emphatic stops, improve the concealment. If mim disappears before fa, improve clear articulation.