Perhaps this example is just meant to be illustrative, but if this is a real case, it seems easy to remove the branch:
local counter = require("core.counter")
local n = 1e9
local c = counter.open("test")
for i = 1,n do
-- Add 9 for odd i, 0 for even.
counter.add(c, 1 + (bit.band(i, 1) * 9))
end
Arguably it's an optimization that compiler could perform instead and a method JIT most likely would. However tracing JIT's optimizations are confined to a linear trace - which I guess exactly the limitation the author wanted to demonstrate.