They will contact the lienholder first to determine the amount outstanding on the lien. Your coverage pays up to the market value of the car. So, if you owe more than the car is worth...too bad for you... your insurance company only pays up to what the car's actual value is.
If your car is declared a total loss, (in which the repairs would exceed a certain % of the market value..sometimes seens as a CCC evaluation, depending on estimate systems) if you don't carry gap insurance, you're screwed. You owe your bank for the outstanding amount.
However, if the damages are less than the market value of the car, you are issued a two-party check. that your lienholder must endorse, before you can cash it. Please contact your lienholder for the specific process.