Function merge_sort() calls itself recursively until the program runs out of stack space and it crashes.
Try changing
q = floor( (p+q)/2 );
to
q = (p+r) / 2;
That won't necessarily solve everything, but it may be a start.
A general hint. If you use meaningful names for variables, such as start, finish, middle, or first, last etc. such mistakes are easier to spot. Code with lots of single-letter variable names is virtually unreadable.
One more thing.
Don't use global variables such as
1 2 3 4
int p;
int q;
int r;
int x;
It means your functions are not self-contained, instead their inner workings are leaking out for the rest of the world to see, like a wounded animal with its guts spilling out.