Classical Green's function I am confused about a classical calculation involving Green's functions.
Suppose $\frac{d^2}{dx^2}G+k^2G=\delta(x)$. Then Fourier theory leads, apart from numerical factors, to
$$G(x)=\int \frac{e^{iqx}}{(q-k)(q+k)}dq,$$
where the integral is to be computed along the real axis. 
Now, there are poles at $q=k$ and $q=-k$. I want to deform the contour in the vicinity of the poles in the form of small half-circunferences. However, these can be traversed clockwise or anti-clockwise, i.e. going over the pole or under it.
In any case, the contour is closed in the counterclockwise manner, so that $q$ has a positive imaginary part (we are assuming $x>0$).
Let the residues from poles 1 and 2 be $R_1$ and $R_2$. Then it seems to me that we have the following possibilities:
1) Both loops go over the poles. Integration around them therefore gives $-R_1/2-R_2/2$. Minus sign comes from orientation and division by two because it is half-circunferences. Final equation is $G-R_1/2-R_2/2=0$ since there are no poles inside the contour.
2) Both loops are under the poles. Integration around them therefore gives $R_1/2+R_2/2$. Final equation is $G+R_1/2+R_2/2=R_1+R_2$ since they are inside the contour.
3) One loop under a pole, say 1, and the other over a pole, say 2. Then $G+R_1/2-R_2/2=R_1$. If the other way aroud, then $G-R_1/2+R_2/2=R_2$.
In all cases we end up with $G=R_1/2+R_2/2$. So it seems the solution is unique.
However, I see everywhere that one can use the choice of contour to match different boundary conditions. So, there should be freedom here. Where is it?
 A: The problem is that you're counting contributions to the contour integral twice. The quantity $G$ is the part of the contour integral that starts at the left end of the real axis and goes to the right end, with some semicircular dents along the way. You should not add $\pm R_i / 2$ to this, to account for the semicircles, because $G$ already contains the semicircles.
Unfortunately, textbooks explain the procedure as "adding a semicircle to the integration path", making it seem like $G$ doesn't include the semicircles. This is a bad explanation; the right way is to keep the integration over the real axis, and add an infinitesimal damping, which pushes the poles off the real axis. You should think of a semicircle indent as really, physically denoting a damping.
Anyway, your equations should read
$$G_1 = 0, \quad G_2 = R_1 + R_2, \quad G_3 = R_1.$$
You might be confused that $G_1 = 0$, but this is completely as expected. In this case, the implicit damping you are choosing is backwards in time, so you end up with the advanced Green's function, which is zero for all $x > 0$. Note that if $x < 0$, we would instead close the contour in the lower-half plane and find
$$G_1 = - R_1 - R_2, \quad G_2 = 0, \quad G_3 = - R_2$$
where $G_2 = 0$ because it is the retarded Green's function. Note that the differences of the $G_i$ across $x = 0$ are all the same, since they are all unit impulse responses.
