As for your claim " Even if a company creates a foundation that gives away money to charity, it is NOT giving shareholders' money away." you are incorrect as all the money in a company belongs to the shareholders after taxes, wages, and debts are paid. That is determined by law. Regardless of your and other's misinterpretations involving corporations and their activities, remember corporation is a definition evolved from "Co-operative Ownership" where a business venture was created by the invested capital that more than one individual provided, such as a water wheel or wind mill powered grain mill owned by multiple farmers who also milled grain of other farmers for a fee, or multiple sailors who pooled resources to buy a ship for their maritime oriented business (fishing, shipping, passenger commerce, etc.). So, if the multiple owners of a corporation choose to give money to a charity, they do not suddenly stop being capitalists and turn into socialists by giving charity. They retain ownership of their means of production, they just choose to give away some of their capital is all. If the SCOTUS does not strictly interpret such actions as within their strict understanding of economics, it does not change what those actions are. The actions of the owners of the capital deciding to spend their capital however they choose in a non-business manner is not an evolution into a new economic theory. A business's true purpose is to provide profit to the owner, if the owner chooses to reinvest those profits within said business, which is their choice. They could give some away out of love of their heart, they could buy groceries, and they could invest in a different venture to diversify their holdings for any number of reasons. Corporations are entities in the sense of Law only for Taxation purposes. as for moral evaluations of charity not applying, you fail in that argument to dig deeper and realize the people owning the business have their own morals and as owners have all the power to spend into them as they feel the need to.
You present the question of how a capitalist economy runs without regulation. Clarification of regulation needs to occur as you have lumped all government action as regulation under a socialist label which is again a red herring. Government under the democratic/republic form of representation which many nations tried to model from Roman Antiquity is based upon the VOLUNTARY FORMATION of government by the people to serve in protection of the common law agreed upon and funded by the people. Taxation was based on paying the government the expenses it cost to protect the capital owned by the citizens. This tax was typically prorated based upon the amount of production capital (e.g. farmland) a citizen owned that was reasonably expected to be protected by the government. Note that this method of proportional taxation of the citizenry based upon land ownership and also proportional voting was also in the origination of the United States of America. Property outside the government's jurisdiction; outside the country, was not protected by the government's laws and forces and not subject to taxation. Hence it was essentially a business arrangement to provide protection for cost to the business owners, essentially a large mutual private security corporation police force/military force. Calling a government police force/military force paid for and operated in the interest of the business owners to protect their capital is hardly socialist. It is however a form of voluntary self-imposed regulation where the citizens get to determine how the government is used.
Socialism, where the state owns the means of production, provides the police force/military force to protect the capital used in production. This expense/extent is decided not by business owners who voluntarily cooperated to form this venture of force, but by some functionary/ruler. The individual who labors to produce is no longer an owner, but a person who's labor product is owned by the state, and is further removed from the power of how much to fund this police force/military force which is allegedly used to protect them. History shows that the laborer is often degraded to a social/political condition of being a 'serf' or government slave. Not owning the means of production, the laborer cannot choose how the capital produced is used and is therefore enslaved to work for the benefit of someone other than themselves.
Capitalism exists in nature as many individuals in nature are inherently responsible for feeding and protecting themselves. The puma concolor (cougar) is generally accepted as being a solo predator. This predator; being solo, must optimize it's hunting opportunities to provide the most food with the least risk of injury. If the cougar is injured, it cannot rely on others to provide for it. If it is too lazy to hunt (sleepy cat) it cannot expect another to hunt for it. It must produce (hunt) the capital (food) it consumes. Orca (Killer Whales: which are actually a member of the porpoise family) are also predators which must hunt form themselves, but choose to live cooperatively in pods for more profitable hunting ventures. A solo orca cannot successfully chase and kill a baby gray whale if its mother is with it. The pod of orca chase the mother/child combo until the child succumbs to fatigue and then kill it when the mother abandons it. Capitalism in the sense of individuals using their privately held means of production in a cooperative sense does exist in nature. No orca is slave to the pod. They can swim away whenever they choose. Check the news for solo orca in the Puget Sound region of Washington State.
I am opposed to enslavement of my fellow human, therefore I am opposed to collectivism. Forcing a person to work and preventing them from taking ownership of their production is thievery in the form of slavery. MANY adherents to the arguments of collectivism make red herring ad homonym attacks on capitalists claiming they enslave the worker with their ownership of their means of production. No person or groups of people hold monopoly of poor behavior, thieves exist in all places. This does not change the fact that when the individual is deprived of the right to own their own means of production, they are serfs/slaves unable to choose their own destiny, regardless who owns the laborer and its produce.