"Unlawful presence" for the purposes of the bans does not accrue while you have a properly-filed Adjustment of Status (I-485) application pending, even if that application is later denied.
From the USCIS Adjudicator's Field Manual Chapter 40.9.2(b)(3)(A):
Note that, if the application is properly filed according to the
regulatory requirements, the applicant will not accrue unlawful
presence, even if it is ultimately determined that the applicant was
not eligible for the benefit in the first place. The accrual of
unlawful presence is tolled until the application is denied.
From the Department of State's Foreign Affairs Manual, 9 FAM 302.11-3(B)(1)(b)(5):
b. DHS has interpreted "period of stay authorized by the Secretary of
Homeland Security" as used in this context to include:
(5) For aliens who have properly filed an application for adjustment
of status to that of a lawful permanent resident (LPR), the entire
period of the pendency of the application, even if the application is
subsequently denied or abandoned, provided the alien (unless seeking
to adjust status under NACARA or HRIFA) did not file for adjustment
"defensively" (i.e., after deportation proceedings had already been
So, if your AOS is denied, the amount of "unlawful presence" you will have accrued before you left is (number of days after your I-94 expired before your I-485 was filed) + (number of days after your I-485 was denied before you left the US). If this is less than 180 days, you trigger no ban upon leaving. If this is more than 180 days/1 year, you trigger a 3-year/10-year, respectively, INA 212(a)(9)(B) ban upon leaving.