The approximate description is that it takes the secondary input's stage, flattens the layer stack (not flattening the whole stage, just the layer stack). This gives you one SdfLayer that is equivalent to the source stage, but with references and payloads preserved as composition arcs. Then SdfCopySpec is used to copy the SdfLayer data from the branch source into the destination stage.
There are lots of details about handling requests to graft in prims that don't exist in the source layer (because the requested prim only exists inside a reference/payload), or when the material is outside the source prim, or there is a transform on an ancestor of the source prim... Most of the details of this stuff can be seen here:
https://github.com/sideeffects/HoudiniUsdBridge/blob/master/src/houdini/lib/H_USD/HUSD/HUSD_MergeInto.C [
github.com]