factored out ir_helpers.c