Q:

Understanding purpose of and difference between given recursive functions

Below are the two pieces of code. I could not understand how the pre-decrement operator in the first code functions. And I also could not understand how both of the codes differ in their functionality.
Code 1:
int foo (int val) { 
  int x = 0; 
  while (val > 0) {
    x = x + foo(--val);
  }
  return val;
}

Code 2:
int bar (int val) {
  int x = 0;
  while (val > 0) {
    x = x + bar(val - 1);
  }
  return val;
}

A:

Consider the original code:
int foo(int val) {
    int x = 0;
    while (val > 0) {
        x = x + foo(val--);  // Post-decrement
    }
    return val;
}

When foo() calls itself recursively, the value passed to the recursive call is the same as the value passed to the current call, so the program will eventually exceed the stack limit and crash.  It won't terminate normally.
Now consider the revised code:
int foo(int val) {
    int x = 0;
    while (val > 0) {
        x = x + foo(--val);  // Pre-decrement
    }
    return val;
}

Now the recursion is finite; if val is positive, then the recursive call is made with a smaller value, so the recursion stops.  If val is negative, there is no recursion, of course.
However, since the code returns val, it will always return either 0 (for a non-negative input, because the loop counts down until val == 0) or what was provided (for a negative input; the loop body is never executed).  The recursion keeps adding 0 to x, so x remains 0 too (but it's a 'set but unread' variable so it could be eliminated, and writing x += foo(val--); would be more idiomatic C).  It would be accurate to say the revised code is equivalent to:
int foo(int val) { return (val < 0) ? val : 0; }

Even returning x doesn't fix all the problems.  It returns 0 for non-negative inputs and 0 for negative inputs (but it doesn't crash):
int foo(int val) {
    int x = 0;
    while (val > 0) {
        x += foo(--val);  // Pre-decrement
    }
    return x;
}

