Both setup() and loop() are functions. As far as the compiler is concerned they are no different from any other function you might create.
The order in which you write functions (including loop() and setup() ) does not matter because the Arduino IDE creates function prototypes in the background to make things easy for you. Consequently the ideas of "before setup()" or "between setup() and loop()" are not meaningful.
What you need to take into account is that some things must be done outside of any function - such as declaring global variables or defining a function, And other things must happen inside a function - such as your program code and the definition of local variables.
x is an 'auto' or 'stack' variable. It is allocated space on the stack when a function is called, and where that space is varies according to the current state of the stack. It only 'lives' for the life of the function. Each time the function is called, it is uninitialized, which means that its value will be whatever garbage happened to have been left on the stack last time the memory there was used.
It is called 'namespace scope'. Unless you explicitly declare a namespace, the namespace of the variable/function is in a global namespace, hence the name global (even though there is little really global about it with regards to a multi file app).
You'll see people familiar with other languages calling it "file scope" or "global scope".
int j = 4; //Namespace scope
void func(){
int j = 6; //Block scope
Serial.print( j ); //Print local j
Serial.print( ::j ); //Print global j
A_Label: //Function scope
}