It is not ad hoc. Whatever bizarre situation you can imagine, it happens hundreds of times every day worldwide.
There is a carefully regulated system for airlines to transmit monies between each other, first formalised in the 1950s. Many airlines have contracts between them called "interline agreements". Without an interline agreement, it is not possible to purchase a ticket that allows connecting flights between the two airlines.
If airline A issued the ticket, then airline A needs to have a ticketing interline agreement with all the other carriers offering transportation on the ticket; this allows those airlines to accept a ticket issued by airline A as a valid and trustworthy financial document. All the major network airlines of the world have interline agreements with each other. Smaller, minor airlines have interline agreements where it is commercially beneficial. Some airlines like Ryanair or Southwest simply do not interline and are not part of the system.
These interline agreements also handle who pays for what and at what rate in what situations. They are generally commercial arrangements that are not public information.
Some carriers have very special and detailed arrangements, for instance, Delta and KLM, who work together very closely on the transatlantic routes. But the simplest arrangement is a standard document called a "Multilateral Interline Traffic Agreement" and is governed by IATA, the International Airline Transport Association. It deals with all the situations you discuss. There is a fixed rate for providing transportation to passengers from other carriers in emergency situations like overbooked flights or weather problems.
IATA also runs a clearing house. Each month, all the airlines present the ticket coupons issued by other carriers that they have collected by offering carriage to passengers under those tickets. There are other financial documents representing other kinds of transportation, debt and credit, as well. The clearing house works out a grand total of who owes what. So if AA owes BA $100m, and BA owes KL $70m, then the clearing house collects $100m from AA, and gives $30m of it to BA, and $70m to KL. This greatly simplifies the number of transactions that need to happen for everyone to get to the right amount.
Which airline-desk (A, B or C) would handle the rebooking and do they then bill the airline which had a delayed flight for the costs?
Under the IATA rules, the forwarding carrier (the one who transported you to the point where your journey is broken, or the one who should transport you next but is unable to do so) is responsible for re-ticketing you onto your next destination. In practice, most passengers will go to the desk of their next onward flight, and this is what is expected. Both airlines have power to revalidate or reissue your ticket accordingly.