How can intermediate goods and final goods be differentiated? The calculation of GDP(using expenditures) is: $C+I+G+Xn$,

where we calculate the spending on final goods and services within a country. However, how exactly are final and intermediate goods differentiated when calculating spending? 

For instance, if one firm sells a product to another firm that adds to that same product and sells it again, how exactly do governments account for this when calculating GDP?
While @M3RS is correct that value added is another approach to computing GDP that handles the final vs. intermediate goods problem more aptly, within the context of the expenditure approach, you would effectively be measuring spending by who's buying it, and this measure is fundamentally imperfect. For example, flour sold by a cooking supply company to a bakery is likely to be counted as an intermediate good. Flour sold at a retail store is likely to be counted as a final good. But, it could be that a relatively small scale bakery buys flour at Costco (I used to work at a wholesale club, and we supplied a lot of small businesses). In that case, despite efforts by the government not to double count, it's really unavoidable. This is why value added is generally better for avoiding double counting.