def createBytecode(irdata):
    instrs = irdata.flat_instructions
    posd, end_pos = _calcMinimumPositions(instrs)

    bytecode = bytearray()
    for ins in instrs:
        if isinstance(ins, (ir.LazyJumpBase, ir.Switch)):
            ins.calcBytecode(posd, irdata.labels)
        bytecode += ins.bytecode
    assert(len(bytecode) == end_pos)

    prev_instr_map = dict(zip(instrs[1:], instrs))
    packed_excepts = []
    for s, e, h, c in irdata.excepts:
        # There appears to be a bug in the JVM where in rare cases, it throws
        # the exception at the address of the instruction _before_ the instruction
        # that actually caused the exception, triggering the wrong handler
        # therefore we include the previous (IR) instruction too
        # Note that this cannot cause an overlap because in that case the previous
        # instruction would just be a label and hence not change anything
        s = prev_instr_map.get(s, s)

        s_off = posd[s]
        e_off = posd[e]
        h_off = posd[h]
        assert(s_off <= e_off)
        if s_off < e_off:
            packed_excepts.append(struct.pack('>HHHH', s_off, e_off, h_off, c))
        else:
            print('Skipping zero width exception!')
            assert(0)

    return bytes(bytecode), packed_excepts
dataset/ETHPy150Open ajinabraham/Mobile-Security-Framework-MobSF/StaticAnalyzer/tools/enjarify/enjarify/jvm/optimization/jumps.py/createBytecode/original