After accept answer (4 yr)
I would expect the function int average_int(int a, int b) to:
  1. Work over the entire range of [INT_MIN..INT_MAX] for all combinations of a and b.
  2. Have the same result as (a+b)/2, as if using wider math.
When int2x exists, @Santiago Alessandri approach works well.
int avgSS(int a, int b) {
  return (int) ( ((int2x) a + b) / 2);
}
Otherwise a variation on @AProgrammer:
Note: wider math is not needed.
int avgC(int a, int b) {
  if ((a < 0) == (b < 0)) {  // a,b same sign
    return a/2 + b/2 + (a%2 + b%2)/2;
  }
  return (a+b)/2;
}
A solution with more tests, but without %
All below solutions "worked" to within 1 of  (a+b)/2 when overflow did not occur, but I was hoping to find one that matched (a+b)/2 for all int.
@Santiago Alessandri Solution works as long as the range of int is narrower than the range of long long - which is usually the case.
((long long)a + (long long)b) / 2
@AProgrammer, the accepted answer, fails about 1/4 of the time to match (a+b)/2.  Example inputs like a == 1, b == -2
a/2 + b/2 + (a%2 + b%2)/2
@Guy Sirton, Solution fails about 1/8 of the time to match (a+b)/2.  Example inputs like a == 1, b == 0
int sgeq = ((a<0)==(b<0));
int avg = ((!sgeq)*(a+b)+sgeq*(b-a))/2 + sgeq*a;
@R.., Solution fails about 1/4 of the time to match (a+b)/2.  Example inputs like a == 1, b == 1
return (a-(a|b)+b)/2+(a|b)/2;
@MatthewD, now deleted solution fails about 5/6 of the time to match (a+b)/2.  Example inputs like a == 1, b == -2
unsigned diff;
signed mean;
if (a > b) {
    diff = a - b;
    mean = b + (diff >> 1);
} else {
    diff = b - a;
    mean = a + (diff >> 1);
}