in reply to adding lines at specific addresses
A regex may be too simple for what you're trying to do. One straightforward way to approach the problem would be to go through the lines in the file one at a time. When you see a (LABEL O n) line, if you have items with n less than that, print those first; if you have items with n equal to that line, print that instead (and arrange to skip all lines until the next (LABEL ...) line); otherwise just print that line and continue printing lines until the next (LABEL ...).