Here is the actual contractual agreement that gove
Post# of 148301
https://www.sifma.org/resources/general/mra-g...nd-msftas/
It's the brokers that are supposed to sort out the owner of record based on the date set by the corporation. Yes they do screw up some times. The person assigned by the corporation to count the votes is given the total count by broker by the DTC. If there is a discrepancy the person in charge of the vote count can go back to individual brokers and have them correct the record of ownership.
ps. You are correct the margin account shares that are loaned are only those bought on margin unless otherwise approved by the shareholder.