Single machine learning algorithm for multiple classes of data : One hot encoder
I know this is late, but the question got bumped by Community, so...

Your discussion and data suggest that what you want to produce is the model
$$y = (3x_1+1)x_2,$$
but that is not a linear model and so linear regression will not find it.  You can try any number of other nonlinear models, the best type depending on your real use-case.  For instance, 


If you really just want a linear model for each value of $x_1$, then it's probably best just to split the data along $x_1$ as you started with.  You might need to examine your motivation behind wanting just "one machine learning model".
You could introduce a new feature, equal to $x_1 x_2$.  This loses some information from option (1) when $x_1$ has more than two values, but it might be suitable.
You could use a tree-based model with linear regression done at each leaf, as in  https://stats.stackexchange.com/questions/78563/regression-tree-algorithm-with-linear-regression-models-in-each-leaf .  If the model fitting procedure decides to split only on $x_1$ and regress only on $x_2$, it mostly recovers option (1), though there's no reason to necessarily expect that.