def offset2line(offset, linestarts):
if len(linestarts) == <NUM_LIT:0> or offset < linestarts[<NUM_LIT:0>][<NUM_LIT:0>]:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>low = <NUM_LIT:0><EOL>high = len(linestarts) - <NUM_LIT:1><EOL>mid = (low + high + <NUM_LIT:1>) // <NUM_LIT:2><EOL>while low <= high:<EOL><INDENT>if linestarts[mid][<NUM_LIT:0>] > offset:<EOL><INDENT>high = mid - <NUM_LIT:1><EOL><DEDENT>elif linestarts[mid][<NUM_LIT:0>] < offset:<EOL><INDENT>low = mid + <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>return linestarts[mid][<NUM_LIT:1>]<EOL><DEDENT>mid = (low + high + <NUM_LIT:1>) // <NUM_LIT:2><EOL>pass<EOL><DEDENT>if mid >= len(linestarts):<EOL><INDENT>return linestarts[len(linestarts)-<NUM_LIT:1>][<NUM_LIT:1>]<EOL><DEDENT>return linestarts[high][<NUM_LIT:1>]<EOL>
linestarts is expected to be a *list) of (offset, line number)
    where both offset and line number are in increasing order.
    Return the closes line number at or below the offset.
    If offset is less than the first line number given in linestarts,
    return line number 0.