Point inside 2D axis aligned rectangle, no branches

2d, algorithm, c

Solution

Given a segment `[x0, x1]`, a point `x` is inside the segment when `(x0 - x) * (x1 - x) <= 0`.

In two dimensions case, you need to do it twice, so it requires two conditionals.

Problem

I'm searching for the most optimized method to detect whether a point is inside an axis aligned rectangle. The easiest solution needs 4 branches (if) which is bad for performance.

Original source