Can someone assist me with building a formula with the logic below?

Formula is in cell F1

If the value in E1 is "Closed"
then
C1-A1 if A1 is populated
If A1 is not populated
then
C1-B1

If the value in E1 is not "Closed"
then
leave F1 blank