All current flow in anything that isn't a superconductor generates heat. In chips, it's mostly flowing in aluminium "metal" layers (why not copper? Nasty chemical interaction with other parts of the silicon, it turns out).
What causes current to flow? Every time a transistor changes state, this can be modeled as a capacitor (the FET gate of the driven logic gate plus parasitic wire capacitance) charging/discharging through the wire and output FET of the previous gate. This is "switching" or "dynamic" power. It's proportional to switching speed and the square of the voltage; hence the drive from 5V to 3.3V to 1.8V for better efficiency.
The insulators are not perfect, and in some places are very thin. Transistors may not be fully "off". If a FET has an off resistance of a megaohm, and you put a million of them in parallel, it looks like a 1 ohm resistor. This is "leakage" power. It's proportional to number of transistors.
I spent a decade working at a startup on power optimisation. :) There are a lot of techniques: speed/leakage tradeoffs ("high k metal gate"), turning off parts of the circuit entirely, clock gating, reduction of clock frequency, sizing and placement.
(A & B)
, this has two inputs and one output. That information that is lost in this process has to go somewhere and becomes entropy (heat)... assuming I understood it enough to describe this. \$\endgroup\$