If you are not used to using a debugger, it's probably a good time to start using one.
Until then, you could add printouts to see what your program is doing:
#include <stdio.h>
int fun(int n) {
    printf("n=%d\n", n);
    int static x = 0;
    if (n >= 0) {
        x = x + 1;        
        int res = fun(n - 1);
        printf("returning fun(%d)\t%d + %d = %d\n", n - 1, res, x, res + x);
        return res + x;
    }
    printf("termination point reached, x = %d\n", x);
    return 0;
}
int main() {
    int a = 5;
    printf("%d\n", fun(a));
}
Output:
n=5
n=4
n=3
n=2
n=1
n=0
n=-1
termination point reached, x = 6
returning fun(-1)   0 + 6 = 6
returning fun(0)    6 + 6 = 12
returning fun(1)    12 + 6 = 18
returning fun(2)    18 + 6 = 24
returning fun(3)    24 + 6 = 30
returning fun(4)    30 + 6 = 36
36