broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code):
    effects = {'push': (0, 1), 'pop': (1, -1), 'dup': (1, 1), 'dup_x1': (2, 1), 'swap': (2, 0),
               'add': (2, -1), 'ifeq': (1, -1), 'goto': (0, 0), 'return': (1, -1)}
    def verify():
        depth = {0: 0}
        work = [0]
        maxd = 0
        while work:
            i = work.pop()
            op, arg = code[i]
            need, delta = effects[op]
            d = depth[i]
            if d < need:
                return ['underflow', i]
            nd = d + delta
            maxd = max(maxd, nd)
            if op == 'goto':
                succ = [arg]
            elif op == 'ifeq':
                succ = [i + 1, arg]
            elif op == 'return':
                succ = []
            else:
                succ = [i + 1]
            for s in succ:
                if s >= len(code):
                    return ['falls-off', i]
                if s in depth:
                    if depth[s] != nd:
                        return ['inconsistent', s]
                else:
                    depth[s] = nd
                    work.append(s)
        return ['ok', maxd]
    try:
        return verify()
    except (IndexError, KeyError):
        return ['vm-crash']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('dup_x1 with one item underflows', ([['push', 1], ['dup_x1', None], ['return', None]],), ['underflow', 1]),
  ('dup_x1 with two items is legal',
   ([['push', 1], ['push', 2], ['dup_x1', None], ['add', None], ['add', None], ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1], ['goto', 3], ['add', None], ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 0], ['ifeq', 4], ['push', 5], ['goto', 5], ['push', 7], ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows', ([['ifeq', 1], ['push', 1], ['return', None]],), ['underflow', 0]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1], ['push', 0], ['ifeq', 4], ['pop', None], ['return', None]],),
   ['inconsistent', 4]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1], ['ifeq', 3], ['push', 9], ['push', 1], ['return', None]],),
   ['inconsistent', 3]),
  ('execution falling off the end', ([['push', 1], ['push', 1]],), ['falls-off', 1]),
  ('negative branch target', ([['push', 1], ['goto', -1], ['return', None]],), ['falls-off', 1]),
  ('swap with one item underflows', ([['push', 1], ['swap', None], ['return', None]],), ['underflow', 1])],
 [('dup_x1 with one item underflows',
   ([['push', 1], ['pop', None], ['push', 1], ['dup_x1', None], ['return', None]],),
   ['underflow', 3]),
  ('dup_x1 with two items is legal',
   ([['push', 1],
     ['pop', None],
     ['push', 1],
     ['push', 2],
     ['dup_x1', None],
     ['add', None],
     ['add', None],
     ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1], ['pop', None], ['push', 1], ['goto', 5], ['add', None], ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 1],
     ['pop', None],
     ['push', 0],
     ['ifeq', 6],
     ['push', 5],
     ['goto', 7],
     ['push', 7],
     ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows',
   ([['push', 1], ['pop', None], ['ifeq', 3], ['push', 1], ['return', None]],),
   ['underflow', 2]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1], ['pop', None], ['push', 1], ['push', 0], ['ifeq', 6], ['pop', None], ['return', None]],),
   ['inconsistent', 6]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1], ['pop', None], ['push', 1], ['ifeq', 5], ['push', 9], ['push', 1], ['return', None]],),
   ['inconsistent', 5]),
  ('execution falling off the end', ([['push', 1], ['pop', None], ['push', 1]],), ['falls-off', 2]),
  ('negative branch target',
   ([['push', 1], ['pop', None], ['push', 1], ['goto', -1], ['return', None]],),
   ['falls-off', 3]),
  ('swap with one item underflows',
   ([['push', 1], ['pop', None], ['push', 1], ['swap', None], ['return', None]],),
   ['underflow', 3])],
 [('dup_x1 with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['dup_x1', None],
     ['return', None]],),
   ['underflow', 5]),
  ('dup_x1 with two items is legal',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['push', 2],
     ['dup_x1', None],
     ['add', None],
     ['add', None],
     ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['goto', 7],
     ['add', None],
     ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 0],
     ['ifeq', 8],
     ['push', 5],
     ['goto', 9],
     ['push', 7],
     ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['ifeq', 5], ['push', 1], ['return', None]],),
   ['underflow', 4]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['push', 0],
     ['ifeq', 8],
     ['pop', None],
     ['return', None]],),
   ['inconsistent', 8]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['ifeq', 7],
     ['push', 9],
     ['push', 1],
     ['return', None]],),
   ['inconsistent', 7]),
  ('execution falling off the end',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['push', 1], ['push', 1]],),
   ['falls-off', 5]),
  ('negative branch target',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['push', 1], ['goto', -1], ['return', None]],),
   ['falls-off', 5]),
  ('swap with one item underflows',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['push', 1], ['swap', None], ['return', None]],),
   ['underflow', 5])],
 [('dup_x1 with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['dup_x1', None],
     ['return', None]],),
   ['underflow', 7]),
  ('dup_x1 with two items is legal',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['push', 2],
     ['dup_x1', None],
     ['add', None],
     ['add', None],
     ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['goto', 9],
     ['add', None],
     ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 0],
     ['ifeq', 10],
     ['push', 5],
     ['goto', 11],
     ['push', 7],
     ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['ifeq', 7],
     ['push', 1],
     ['return', None]],),
   ['underflow', 6]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['push', 0],
     ['ifeq', 10],
     ['pop', None],
     ['return', None]],),
   ['inconsistent', 10]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['ifeq', 9],
     ['push', 9],
     ['push', 1],
     ['return', None]],),
   ['inconsistent', 9]),
  ('execution falling off the end',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['push', 3], ['pop', None], ['push', 1]],),
   ['falls-off', 6]),
  ('negative branch target',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['goto', -1],
     ['return', None]],),
   ['falls-off', 7]),
  ('swap with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['swap', None],
     ['return', None]],),
   ['underflow', 7])],
 [('dup_x1 with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['dup_x1', None],
     ['return', None]],),
   ['underflow', 9]),
  ('dup_x1 with two items is legal',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['push', 2],
     ['dup_x1', None],
     ['add', None],
     ['add', None],
     ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['goto', 11],
     ['add', None],
     ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 0],
     ['ifeq', 12],
     ['push', 5],
     ['goto', 13],
     ['push', 7],
     ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['ifeq', 9],
     ['push', 1],
     ['return', None]],),
   ['underflow', 8]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['push', 0],
     ['ifeq', 12],
     ['pop', None],
     ['return', None]],),
   ['inconsistent', 12]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['ifeq', 11],
     ['push', 9],
     ['push', 1],
     ['return', None]],),
   ['inconsistent', 11]),
  ('execution falling off the end',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['push', 1]],),
   ['falls-off', 9]),
  ('negative branch target',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['goto', -1],
     ['return', None]],),
   ['falls-off', 9]),
  ('swap with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['swap', None],
     ['return', None]],),
   ['underflow', 9])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code):
    effects = {'push': (0, 1), 'pop': (1, -1), 'dup': (1, 1), 'dup_x1': (2, 1), 'swap': (2, 0),
               'add': (2, -1), 'ifeq': (1, -1), 'goto': (0, 0), 'return': (1, -1)}
    def verify():
        depth = {0: 0}
        work = [0]
        maxd = 0
        while work:
            i = work.pop()
            op, arg = code[i]
            need, delta = effects[op]
            d = depth[i]
            if d < need:
                return ['underflow', i]
            nd = d + delta
            maxd = max(maxd, nd)
            if op == 'goto':
                succ = [arg]
            elif op == 'ifeq':
                succ = [i + 1, arg]
            elif op == 'return':
                succ = []
            else:
                succ = [i + 1]
            for s in succ:
                if s < 0 or s > len(code):
                    return ['falls-off', i]
                if s in depth:
                    if depth[s] != nd:
                        return ['inconsistent', s]
                else:
                    depth[s] = nd
                    work.append(s)
        return ['ok', maxd]
    try:
        return verify()
    except (IndexError, KeyError):
        return ['vm-crash']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('dup_x1 with one item underflows', ([['push', 1], ['dup_x1', None], ['return', None]],), ['underflow', 1]),
  ('dup_x1 with two items is legal',
   ([['push', 1], ['push', 2], ['dup_x1', None], ['add', None], ['add', None], ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1], ['goto', 3], ['add', None], ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 0], ['ifeq', 4], ['push', 5], ['goto', 5], ['push', 7], ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows', ([['ifeq', 1], ['push', 1], ['return', None]],), ['underflow', 0]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1], ['push', 0], ['ifeq', 4], ['pop', None], ['return', None]],),
   ['inconsistent', 4]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1], ['ifeq', 3], ['push', 9], ['push', 1], ['return', None]],),
   ['inconsistent', 3]),
  ('execution falling off the end', ([['push', 1], ['push', 1]],), ['falls-off', 1]),
  ('negative branch target', ([['push', 1], ['goto', -1], ['return', None]],), ['falls-off', 1]),
  ('swap with one item underflows', ([['push', 1], ['swap', None], ['return', None]],), ['underflow', 1])],
 [('dup_x1 with one item underflows',
   ([['push', 1], ['pop', None], ['push', 1], ['dup_x1', None], ['return', None]],),
   ['underflow', 3]),
  ('dup_x1 with two items is legal',
   ([['push', 1],
     ['pop', None],
     ['push', 1],
     ['push', 2],
     ['dup_x1', None],
     ['add', None],
     ['add', None],
     ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1], ['pop', None], ['push', 1], ['goto', 5], ['add', None], ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 1],
     ['pop', None],
     ['push', 0],
     ['ifeq', 6],
     ['push', 5],
     ['goto', 7],
     ['push', 7],
     ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows',
   ([['push', 1], ['pop', None], ['ifeq', 3], ['push', 1], ['return', None]],),
   ['underflow', 2]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1], ['pop', None], ['push', 1], ['push', 0], ['ifeq', 6], ['pop', None], ['return', None]],),
   ['inconsistent', 6]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1], ['pop', None], ['push', 1], ['ifeq', 5], ['push', 9], ['push', 1], ['return', None]],),
   ['inconsistent', 5]),
  ('execution falling off the end', ([['push', 1], ['pop', None], ['push', 1]],), ['falls-off', 2]),
  ('negative branch target',
   ([['push', 1], ['pop', None], ['push', 1], ['goto', -1], ['return', None]],),
   ['falls-off', 3]),
  ('swap with one item underflows',
   ([['push', 1], ['pop', None], ['push', 1], ['swap', None], ['return', None]],),
   ['underflow', 3])],
 [('dup_x1 with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['dup_x1', None],
     ['return', None]],),
   ['underflow', 5]),
  ('dup_x1 with two items is legal',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['push', 2],
     ['dup_x1', None],
     ['add', None],
     ['add', None],
     ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['goto', 7],
     ['add', None],
     ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 0],
     ['ifeq', 8],
     ['push', 5],
     ['goto', 9],
     ['push', 7],
     ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['ifeq', 5], ['push', 1], ['return', None]],),
   ['underflow', 4]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['push', 0],
     ['ifeq', 8],
     ['pop', None],
     ['return', None]],),
   ['inconsistent', 8]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['ifeq', 7],
     ['push', 9],
     ['push', 1],
     ['return', None]],),
   ['inconsistent', 7]),
  ('execution falling off the end',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['push', 1], ['push', 1]],),
   ['falls-off', 5]),
  ('negative branch target',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['push', 1], ['goto', -1], ['return', None]],),
   ['falls-off', 5]),
  ('swap with one item underflows',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['push', 1], ['swap', None], ['return', None]],),
   ['underflow', 5])],
 [('dup_x1 with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['dup_x1', None],
     ['return', None]],),
   ['underflow', 7]),
  ('dup_x1 with two items is legal',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['push', 2],
     ['dup_x1', None],
     ['add', None],
     ['add', None],
     ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['goto', 9],
     ['add', None],
     ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 0],
     ['ifeq', 10],
     ['push', 5],
     ['goto', 11],
     ['push', 7],
     ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['ifeq', 7],
     ['push', 1],
     ['return', None]],),
   ['underflow', 6]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['push', 0],
     ['ifeq', 10],
     ['pop', None],
     ['return', None]],),
   ['inconsistent', 10]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['ifeq', 9],
     ['push', 9],
     ['push', 1],
     ['return', None]],),
   ['inconsistent', 9]),
  ('execution falling off the end',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['push', 3], ['pop', None], ['push', 1]],),
   ['falls-off', 6]),
  ('negative branch target',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['goto', -1],
     ['return', None]],),
   ['falls-off', 7]),
  ('swap with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['swap', None],
     ['return', None]],),
   ['underflow', 7])],
 [('dup_x1 with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['dup_x1', None],
     ['return', None]],),
   ['underflow', 9]),
  ('dup_x1 with two items is legal',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['push', 2],
     ['dup_x1', None],
     ['add', None],
     ['add', None],
     ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['goto', 11],
     ['add', None],
     ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 0],
     ['ifeq', 12],
     ['push', 5],
     ['goto', 13],
     ['push', 7],
     ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['ifeq', 9],
     ['push', 1],
     ['return', None]],),
   ['underflow', 8]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['push', 0],
     ['ifeq', 12],
     ['pop', None],
     ['return', None]],),
   ['inconsistent', 12]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['ifeq', 11],
     ['push', 9],
     ['push', 1],
     ['return', None]],),
   ['inconsistent', 11]),
  ('execution falling off the end',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['push', 1]],),
   ['falls-off', 9]),
  ('negative branch target',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['goto', -1],
     ['return', None]],),
   ['falls-off', 9]),
  ('swap with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['swap', None],
     ['return', None]],),
   ['underflow', 9])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A branch to -1 verifies the last instruction instead of being rejected.

code is a list of [op, arg]. Stack effects (required, delta): push (0,+1), pop (1,-1), dup (1,+1), dup_x1 (2,+1), swap (2,0), add (2,-1), ifeq (1,-1; successors fallthrough and arg), goto (0,0; only arg), return (1,-1; none). Dataflow from index 0 with depth 0: report ["underflow", i], ["falls-off", i] for a successor outside the code, ["inconsistent", s] when a merge sees two depths, else ["ok", max depth]. Unreachable code is never examined.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code):
    effects = {'push': (0, 1), 'pop': (1, -1), 'dup': (1, 1), 'dup_x1': (2, 1), 'swap': (2, 0),
               'add': (2, -1), 'ifeq': (1, -1), 'goto': (0, 0), 'return': (1, -1)}
    def verify():
        depth = {0: 0}
        work = [0]
        maxd = 0
        while work:
            i = work.pop()
            op, arg = code[i]
            need, delta = effects[op]
            d = depth[i]
            if d <= need:
                return ['underflow', i]
            nd = d + delta
            maxd = max(maxd, nd)
            if op == 'goto':
                succ = [arg]
            elif op == 'ifeq':
                succ = [i + 1, arg]
            elif op == 'return':
                succ = []
            else:
                succ = [i + 1]
            for s in succ:
                if s < 0 or s >= len(code):
                    return ['falls-off', i]
                if s in depth:
                    if depth[s] != nd:
                        return ['inconsistent', s]
                else:
                    depth[s] = nd
                    work.append(s)
        return ['ok', maxd]
    try:
        return verify()
    except (IndexError, KeyError):
        return ['vm-crash']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('dup_x1 with one item underflows', ([['push', 1], ['dup_x1', None], ['return', None]],), ['underflow', 1]),
  ('dup_x1 with two items is legal',
   ([['push', 1], ['push', 2], ['dup_x1', None], ['add', None], ['add', None], ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1], ['goto', 3], ['add', None], ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 0], ['ifeq', 4], ['push', 5], ['goto', 5], ['push', 7], ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows', ([['ifeq', 1], ['push', 1], ['return', None]],), ['underflow', 0]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1], ['push', 0], ['ifeq', 4], ['pop', None], ['return', None]],),
   ['inconsistent', 4]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1], ['ifeq', 3], ['push', 9], ['push', 1], ['return', None]],),
   ['inconsistent', 3]),
  ('execution falling off the end', ([['push', 1], ['push', 1]],), ['falls-off', 1]),
  ('negative branch target', ([['push', 1], ['goto', -1], ['return', None]],), ['falls-off', 1]),
  ('swap with one item underflows', ([['push', 1], ['swap', None], ['return', None]],), ['underflow', 1])],
 [('dup_x1 with one item underflows',
   ([['push', 1], ['pop', None], ['push', 1], ['dup_x1', None], ['return', None]],),
   ['underflow', 3]),
  ('dup_x1 with two items is legal',
   ([['push', 1],
     ['pop', None],
     ['push', 1],
     ['push', 2],
     ['dup_x1', None],
     ['add', None],
     ['add', None],
     ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1], ['pop', None], ['push', 1], ['goto', 5], ['add', None], ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 1],
     ['pop', None],
     ['push', 0],
     ['ifeq', 6],
     ['push', 5],
     ['goto', 7],
     ['push', 7],
     ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows',
   ([['push', 1], ['pop', None], ['ifeq', 3], ['push', 1], ['return', None]],),
   ['underflow', 2]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1], ['pop', None], ['push', 1], ['push', 0], ['ifeq', 6], ['pop', None], ['return', None]],),
   ['inconsistent', 6]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1], ['pop', None], ['push', 1], ['ifeq', 5], ['push', 9], ['push', 1], ['return', None]],),
   ['inconsistent', 5]),
  ('execution falling off the end', ([['push', 1], ['pop', None], ['push', 1]],), ['falls-off', 2]),
  ('negative branch target',
   ([['push', 1], ['pop', None], ['push', 1], ['goto', -1], ['return', None]],),
   ['falls-off', 3]),
  ('swap with one item underflows',
   ([['push', 1], ['pop', None], ['push', 1], ['swap', None], ['return', None]],),
   ['underflow', 3])],
 [('dup_x1 with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['dup_x1', None],
     ['return', None]],),
   ['underflow', 5]),
  ('dup_x1 with two items is legal',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['push', 2],
     ['dup_x1', None],
     ['add', None],
     ['add', None],
     ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['goto', 7],
     ['add', None],
     ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 0],
     ['ifeq', 8],
     ['push', 5],
     ['goto', 9],
     ['push', 7],
     ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['ifeq', 5], ['push', 1], ['return', None]],),
   ['underflow', 4]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['push', 0],
     ['ifeq', 8],
     ['pop', None],
     ['return', None]],),
   ['inconsistent', 8]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['ifeq', 7],
     ['push', 9],
     ['push', 1],
     ['return', None]],),
   ['inconsistent', 7]),
  ('execution falling off the end',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['push', 1], ['push', 1]],),
   ['falls-off', 5]),
  ('negative branch target',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['push', 1], ['goto', -1], ['return', None]],),
   ['falls-off', 5]),
  ('swap with one item underflows',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['push', 1], ['swap', None], ['return', None]],),
   ['underflow', 5])],
 [('dup_x1 with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['dup_x1', None],
     ['return', None]],),
   ['underflow', 7]),
  ('dup_x1 with two items is legal',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['push', 2],
     ['dup_x1', None],
     ['add', None],
     ['add', None],
     ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['goto', 9],
     ['add', None],
     ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 0],
     ['ifeq', 10],
     ['push', 5],
     ['goto', 11],
     ['push', 7],
     ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['ifeq', 7],
     ['push', 1],
     ['return', None]],),
   ['underflow', 6]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['push', 0],
     ['ifeq', 10],
     ['pop', None],
     ['return', None]],),
   ['inconsistent', 10]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['ifeq', 9],
     ['push', 9],
     ['push', 1],
     ['return', None]],),
   ['inconsistent', 9]),
  ('execution falling off the end',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['push', 3], ['pop', None], ['push', 1]],),
   ['falls-off', 6]),
  ('negative branch target',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['goto', -1],
     ['return', None]],),
   ['falls-off', 7]),
  ('swap with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['swap', None],
     ['return', None]],),
   ['underflow', 7])],
 [('dup_x1 with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['dup_x1', None],
     ['return', None]],),
   ['underflow', 9]),
  ('dup_x1 with two items is legal',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['push', 2],
     ['dup_x1', None],
     ['add', None],
     ['add', None],
     ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['goto', 11],
     ['add', None],
     ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 0],
     ['ifeq', 12],
     ['push', 5],
     ['goto', 13],
     ['push', 7],
     ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['ifeq', 9],
     ['push', 1],
     ['return', None]],),
   ['underflow', 8]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['push', 0],
     ['ifeq', 12],
     ['pop', None],
     ['return', None]],),
   ['inconsistent', 12]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['ifeq', 11],
     ['push', 9],
     ['push', 1],
     ['return', None]],),
   ['inconsistent', 11]),
  ('execution falling off the end',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['push', 1]],),
   ['falls-off', 9]),
  ('negative branch target',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['goto', -1],
     ['return', None]],),
   ['falls-off', 9]),
  ('swap with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['swap', None],
     ['return', None]],),
   ['underflow', 9])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code):
    effects = {'push': (0, 1), 'pop': (1, -1), 'dup': (1, 1), 'dup_x1': (2, 1), 'swap': (2, 0),
               'add': (2, -1), 'ifeq': (1, -1), 'goto': (0, 0), 'return': (1, -1)}
    def verify():
        depth = {0: 0}
        work = [0]
        maxd = 0
        while work:
            i = work.pop()
            op, arg = code[i]
            need, delta = effects[op]
            d = depth[i]
            if d + delta < 0:
                return ['underflow', i]
            nd = d + delta
            maxd = max(maxd, nd)
            if op == 'goto':
                succ = [arg]
            elif op == 'ifeq':
                succ = [i + 1, arg]
            elif op == 'return':
                succ = []
            else:
                succ = [i + 1]
            for s in succ:
                if s < 0 or s >= len(code):
                    return ['falls-off', i]
                if s in depth:
                    if depth[s] != nd:
                        return ['inconsistent', s]
                else:
                    depth[s] = nd
                    work.append(s)
        return ['ok', maxd]
    try:
        return verify()
    except (IndexError, KeyError):
        return ['vm-crash']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('dup_x1 with one item underflows', ([['push', 1], ['dup_x1', None], ['return', None]],), ['underflow', 1]),
  ('dup_x1 with two items is legal',
   ([['push', 1], ['push', 2], ['dup_x1', None], ['add', None], ['add', None], ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1], ['goto', 3], ['add', None], ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 0], ['ifeq', 4], ['push', 5], ['goto', 5], ['push', 7], ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows', ([['ifeq', 1], ['push', 1], ['return', None]],), ['underflow', 0]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1], ['push', 0], ['ifeq', 4], ['pop', None], ['return', None]],),
   ['inconsistent', 4]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1], ['ifeq', 3], ['push', 9], ['push', 1], ['return', None]],),
   ['inconsistent', 3]),
  ('execution falling off the end', ([['push', 1], ['push', 1]],), ['falls-off', 1]),
  ('negative branch target', ([['push', 1], ['goto', -1], ['return', None]],), ['falls-off', 1]),
  ('swap with one item underflows', ([['push', 1], ['swap', None], ['return', None]],), ['underflow', 1])],
 [('dup_x1 with one item underflows',
   ([['push', 1], ['pop', None], ['push', 1], ['dup_x1', None], ['return', None]],),
   ['underflow', 3]),
  ('dup_x1 with two items is legal',
   ([['push', 1],
     ['pop', None],
     ['push', 1],
     ['push', 2],
     ['dup_x1', None],
     ['add', None],
     ['add', None],
     ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1], ['pop', None], ['push', 1], ['goto', 5], ['add', None], ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 1],
     ['pop', None],
     ['push', 0],
     ['ifeq', 6],
     ['push', 5],
     ['goto', 7],
     ['push', 7],
     ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows',
   ([['push', 1], ['pop', None], ['ifeq', 3], ['push', 1], ['return', None]],),
   ['underflow', 2]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1], ['pop', None], ['push', 1], ['push', 0], ['ifeq', 6], ['pop', None], ['return', None]],),
   ['inconsistent', 6]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1], ['pop', None], ['push', 1], ['ifeq', 5], ['push', 9], ['push', 1], ['return', None]],),
   ['inconsistent', 5]),
  ('execution falling off the end', ([['push', 1], ['pop', None], ['push', 1]],), ['falls-off', 2]),
  ('negative branch target',
   ([['push', 1], ['pop', None], ['push', 1], ['goto', -1], ['return', None]],),
   ['falls-off', 3]),
  ('swap with one item underflows',
   ([['push', 1], ['pop', None], ['push', 1], ['swap', None], ['return', None]],),
   ['underflow', 3])],
 [('dup_x1 with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['dup_x1', None],
     ['return', None]],),
   ['underflow', 5]),
  ('dup_x1 with two items is legal',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['push', 2],
     ['dup_x1', None],
     ['add', None],
     ['add', None],
     ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['goto', 7],
     ['add', None],
     ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 0],
     ['ifeq', 8],
     ['push', 5],
     ['goto', 9],
     ['push', 7],
     ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['ifeq', 5], ['push', 1], ['return', None]],),
   ['underflow', 4]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['push', 0],
     ['ifeq', 8],
     ['pop', None],
     ['return', None]],),
   ['inconsistent', 8]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 1],
     ['ifeq', 7],
     ['push', 9],
     ['push', 1],
     ['return', None]],),
   ['inconsistent', 7]),
  ('execution falling off the end',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['push', 1], ['push', 1]],),
   ['falls-off', 5]),
  ('negative branch target',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['push', 1], ['goto', -1], ['return', None]],),
   ['falls-off', 5]),
  ('swap with one item underflows',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['push', 1], ['swap', None], ['return', None]],),
   ['underflow', 5])],
 [('dup_x1 with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['dup_x1', None],
     ['return', None]],),
   ['underflow', 7]),
  ('dup_x1 with two items is legal',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['push', 2],
     ['dup_x1', None],
     ['add', None],
     ['add', None],
     ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['goto', 9],
     ['add', None],
     ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 0],
     ['ifeq', 10],
     ['push', 5],
     ['goto', 11],
     ['push', 7],
     ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['ifeq', 7],
     ['push', 1],
     ['return', None]],),
   ['underflow', 6]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['push', 0],
     ['ifeq', 10],
     ['pop', None],
     ['return', None]],),
   ['inconsistent', 10]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['ifeq', 9],
     ['push', 9],
     ['push', 1],
     ['return', None]],),
   ['inconsistent', 9]),
  ('execution falling off the end',
   ([['push', 1], ['pop', None], ['push', 2], ['pop', None], ['push', 3], ['pop', None], ['push', 1]],),
   ['falls-off', 6]),
  ('negative branch target',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['goto', -1],
     ['return', None]],),
   ['falls-off', 7]),
  ('swap with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 1],
     ['swap', None],
     ['return', None]],),
   ['underflow', 7])],
 [('dup_x1 with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['dup_x1', None],
     ['return', None]],),
   ['underflow', 9]),
  ('dup_x1 with two items is legal',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['push', 2],
     ['dup_x1', None],
     ['add', None],
     ['add', None],
     ['return', None]],),
   ['ok', 3]),
  ('regression: dead code after goto is not verified',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['goto', 11],
     ['add', None],
     ['return', None]],),
   ['ok', 1]),
  ('if/else arms merge at equal depth',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 0],
     ['ifeq', 12],
     ['push', 5],
     ['goto', 13],
     ['push', 7],
     ['return', None]],),
   ['ok', 1]),
  ('ifeq on empty stack underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['ifeq', 9],
     ['push', 1],
     ['return', None]],),
   ['underflow', 8]),
  ('deeper arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['push', 0],
     ['ifeq', 12],
     ['pop', None],
     ['return', None]],),
   ['inconsistent', 12]),
  ('shallower arm reaching merge first is inconsistent',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['ifeq', 11],
     ['push', 9],
     ['push', 1],
     ['return', None]],),
   ['inconsistent', 11]),
  ('execution falling off the end',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['push', 1]],),
   ['falls-off', 9]),
  ('negative branch target',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['goto', -1],
     ['return', None]],),
   ['falls-off', 9]),
  ('swap with one item underflows',
   ([['push', 1],
     ['pop', None],
     ['push', 2],
     ['pop', None],
     ['push', 3],
     ['pop', None],
     ['push', 4],
     ['pop', None],
     ['push', 1],
     ['swap', None],
     ['return', None]],),
   ['underflow', 9])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Any instruction whose required operands exactly fill the stack is rejected.

code is a list of [op, arg]. Stack effects (required, delta): push (0,+1), pop (1,-1), dup (1,+1), dup_x1 (2,+1), swap (2,0), add (2,-1), ifeq (1,-1; successors fallthrough and arg), goto (0,0; only arg), return (1,-1; none). Dataflow from index 0 with depth 0: report ["underflow", i], ["falls-off", i] for a successor outside the code, ["inconsistent", s] when a merge sees two depths, else ["ok", max depth]. Unreachable code is never examined.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code, max_depth, fuel):
    def run():
        frames = [{'locals': [0] * 4, 'stack': [], 'ret': None}]
        pc = 0
        for _ in range(fuel):
            f = frames[-1]
            ins = code[pc]
            op = ins[0]
            if op == 'push':
                f['stack'].append(ins[1])
                pc += 1
            elif op == 'load':
                f['stack'].append(f['locals'][ins[1]])
                pc += 1
            elif op == 'store':
                f['locals'][ins[1]] = f['stack'].pop()
                pc += 1
            elif op in ('add', 'sub', 'mul'):
                b = f['stack'].pop()
                a = f['stack'].pop()
                f['stack'].append(a + b if op == 'add' else a - b if op == 'sub' else a * b)
                pc += 1
            elif op == 'jz':
                pc = ins[1] if f['stack'].pop() == 0 else pc + 1
            elif op == 'jmp':
                pc = ins[1]
            elif op == 'call':
                target, nargs, nlocals = ins[1], ins[2], ins[3]
                if len(frames) >= max_depth:
                    return ['StackOverflowError', len(frames)]
                args = f['stack'][len(f['stack']) - nargs:][::-1]
                del f['stack'][len(f['stack']) - nargs:]
                frames.append({'locals': args + [0] * (nlocals - nargs), 'stack': [], 'ret': pc + 1})
                pc = target
            elif op == 'ret':
                value = f['stack'].pop()
                frames.pop()
                frames[-1]['stack'].append(value)
                pc = f['ret']
            else:
                return ['halt', f['stack']]
        return ['fuel', pc]
    try:
        return run()
    except (IndexError, TypeError):
        return ['vm-fault']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('two-argument call binds first argument to slot 0',
   ([['push', 21], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [18]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 8], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']], 10, 100),
   ['halt', [3]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 1],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [4]]),
  ('regression: recursive factorial',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [6]]),
  ('recursion depth exactly at the limit',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    5,
    500),
   ['halt', [6]]),
  ('recursion one frame over the limit',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    4,
    500),
   ['StackOverflowError', 4]),
  ('control: fuel exhaustion',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])],
 [('two-argument call binds first argument to slot 0',
   ([['push', 22], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [19]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 9], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']], 10, 100),
   ['halt', [4]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 2],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [10]]),
  ('regression: recursive factorial',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [24]]),
  ('recursion depth exactly at the limit',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    6,
    500),
   ['halt', [24]]),
  ('recursion one frame over the limit',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    5,
    500),
   ['StackOverflowError', 5]),
  ('control: fuel exhaustion',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])],
 [('two-argument call binds first argument to slot 0',
   ([['push', 23], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [20]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 10], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']],
    10,
    100),
   ['halt', [5]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 3],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [18]]),
  ('regression: recursive factorial',
   ([['push', 2],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [2]]),
  ('recursion depth exactly at the limit',
   ([['push', 2],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    4,
    500),
   ['halt', [2]]),
  ('recursion one frame over the limit',
   ([['push', 2],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    3,
    500),
   ['StackOverflowError', 3]),
  ('control: fuel exhaustion',
   ([['push', 2],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])],
 [('two-argument call binds first argument to slot 0',
   ([['push', 24], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [21]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 11], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']],
    10,
    100),
   ['halt', [6]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 4],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [28]]),
  ('regression: recursive factorial',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [6]]),
  ('recursion depth exactly at the limit',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    5,
    500),
   ['halt', [6]]),
  ('recursion one frame over the limit',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    4,
    500),
   ['StackOverflowError', 4]),
  ('control: fuel exhaustion',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])],
 [('two-argument call binds first argument to slot 0',
   ([['push', 25], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [22]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 12], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']],
    10,
    100),
   ['halt', [7]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 5],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [40]]),
  ('regression: recursive factorial',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [24]]),
  ('recursion depth exactly at the limit',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    6,
    500),
   ['halt', [24]]),
  ('recursion one frame over the limit',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    5,
    500),
   ['StackOverflowError', 5]),
  ('control: fuel exhaustion',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code, max_depth, fuel):
    def run():
        frames = [{'locals': [0] * 4, 'stack': [], 'ret': None}]
        pc = 0
        for _ in range(fuel):
            f = frames[-1]
            ins = code[pc]
            op = ins[0]
            if op == 'push':
                f['stack'].append(ins[1])
                pc += 1
            elif op == 'load':
                f['stack'].append(f['locals'][ins[1]])
                pc += 1
            elif op == 'store':
                f['locals'][ins[1]] = f['stack'].pop()
                pc += 1
            elif op in ('add', 'sub', 'mul'):
                b = f['stack'].pop()
                a = f['stack'].pop()
                f['stack'].append(a + b if op == 'add' else a - b if op == 'sub' else a * b)
                pc += 1
            elif op == 'jz':
                pc = ins[1] if f['stack'].pop() == 0 else pc + 1
            elif op == 'jmp':
                pc = ins[1]
            elif op == 'call':
                target, nargs, nlocals = ins[1], ins[2], ins[3]
                if len(frames) >= max_depth:
                    return ['StackOverflowError', len(frames)]
                args = [f['stack'][-1]] + f['stack'][len(f['stack']) - nargs:-1]
                del f['stack'][len(f['stack']) - nargs:]
                frames.append({'locals': args + [0] * (nlocals - nargs), 'stack': [], 'ret': pc + 1})
                pc = target
            elif op == 'ret':
                value = f['stack'].pop()
                frames.pop()
                frames[-1]['stack'].append(value)
                pc = f['ret']
            else:
                return ['halt', f['stack']]
        return ['fuel', pc]
    try:
        return run()
    except (IndexError, TypeError):
        return ['vm-fault']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('two-argument call binds first argument to slot 0',
   ([['push', 21], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [18]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 8], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']], 10, 100),
   ['halt', [3]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 1],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [4]]),
  ('regression: recursive factorial',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [6]]),
  ('recursion depth exactly at the limit',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    5,
    500),
   ['halt', [6]]),
  ('recursion one frame over the limit',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    4,
    500),
   ['StackOverflowError', 4]),
  ('control: fuel exhaustion',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])],
 [('two-argument call binds first argument to slot 0',
   ([['push', 22], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [19]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 9], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']], 10, 100),
   ['halt', [4]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 2],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [10]]),
  ('regression: recursive factorial',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [24]]),
  ('recursion depth exactly at the limit',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    6,
    500),
   ['halt', [24]]),
  ('recursion one frame over the limit',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    5,
    500),
   ['StackOverflowError', 5]),
  ('control: fuel exhaustion',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])],
 [('two-argument call binds first argument to slot 0',
   ([['push', 23], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [20]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 10], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']],
    10,
    100),
   ['halt', [5]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 3],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [18]]),
  ('regression: recursive factorial',
   ([['push', 2],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [2]]),
  ('recursion depth exactly at the limit',
   ([['push', 2],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    4,
    500),
   ['halt', [2]]),
  ('recursion one frame over the limit',
   ([['push', 2],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    3,
    500),
   ['StackOverflowError', 3]),
  ('control: fuel exhaustion',
   ([['push', 2],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])],
 [('two-argument call binds first argument to slot 0',
   ([['push', 24], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [21]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 11], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']],
    10,
    100),
   ['halt', [6]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 4],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [28]]),
  ('regression: recursive factorial',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [6]]),
  ('recursion depth exactly at the limit',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    5,
    500),
   ['halt', [6]]),
  ('recursion one frame over the limit',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    4,
    500),
   ['StackOverflowError', 4]),
  ('control: fuel exhaustion',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])],
 [('two-argument call binds first argument to slot 0',
   ([['push', 25], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [22]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 12], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']],
    10,
    100),
   ['halt', [7]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 5],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [40]]),
  ('regression: recursive factorial',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [24]]),
  ('recursion depth exactly at the limit',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    6,
    500),
   ['halt', [24]]),
  ('recursion one frame over the limit',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    5,
    500),
   ['StackOverflowError', 5]),
  ('control: fuel exhaustion',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Two-argument functions see their parameters swapped; sub(a, b) returns b - a.

Instructions: push v, load k, store k, add/sub/mul (second-from-top op top), jz t, jmp t, call t nargs nlocals, ret, halt. call pops nargs values (the first pushed becomes local 0), appends zero locals up to nlocals, records return pc = call pc + 1, and raises ["StackOverflowError", frames] when the frame count already equals max_depth. ret pops the result, discards the callee frame, pushes the result on the caller stack and resumes at the saved pc. Each executed instruction costs one fuel; running out returns ["fuel", pc]; host faults are ["vm-fault"].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code, max_depth, fuel):
    def run():
        frames = [{'locals': [0] * 4, 'stack': [], 'ret': None}]
        pc = 0
        for _ in range(fuel):
            f = frames[-1]
            ins = code[pc]
            op = ins[0]
            if op == 'push':
                f['stack'].append(ins[1])
                pc += 1
            elif op == 'load':
                f['stack'].append(f['locals'][ins[1]])
                pc += 1
            elif op == 'store':
                f['locals'][ins[1]] = f['stack'].pop()
                pc += 1
            elif op in ('add', 'sub', 'mul'):
                b = f['stack'].pop()
                a = f['stack'].pop()
                f['stack'].append(a + b if op == 'add' else a - b if op == 'sub' else a * b)
                pc += 1
            elif op == 'jz':
                pc = ins[1] if f['stack'].pop() == 0 else pc + 1
            elif op == 'jmp':
                pc = ins[1]
            elif op == 'call':
                target, nargs, nlocals = ins[1], ins[2], ins[3]
                if len(frames) >= max_depth:
                    return ['StackOverflowError', len(frames)]
                args = f['stack'][len(f['stack']) - nargs:]
                del f['stack'][-nargs:]
                frames.append({'locals': args + [0] * (nlocals - nargs), 'stack': [], 'ret': pc + 1})
                pc = target
            elif op == 'ret':
                value = f['stack'].pop()
                frames.pop()
                frames[-1]['stack'].append(value)
                pc = f['ret']
            else:
                return ['halt', f['stack']]
        return ['fuel', pc]
    try:
        return run()
    except (IndexError, TypeError):
        return ['vm-fault']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('two-argument call binds first argument to slot 0',
   ([['push', 21], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [18]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 8], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']], 10, 100),
   ['halt', [3]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 1],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [4]]),
  ('regression: recursive factorial',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [6]]),
  ('recursion depth exactly at the limit',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    5,
    500),
   ['halt', [6]]),
  ('recursion one frame over the limit',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    4,
    500),
   ['StackOverflowError', 4]),
  ('control: fuel exhaustion',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])],
 [('two-argument call binds first argument to slot 0',
   ([['push', 22], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [19]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 9], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']], 10, 100),
   ['halt', [4]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 2],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [10]]),
  ('regression: recursive factorial',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [24]]),
  ('recursion depth exactly at the limit',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    6,
    500),
   ['halt', [24]]),
  ('recursion one frame over the limit',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    5,
    500),
   ['StackOverflowError', 5]),
  ('control: fuel exhaustion',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])],
 [('two-argument call binds first argument to slot 0',
   ([['push', 23], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [20]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 10], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']],
    10,
    100),
   ['halt', [5]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 3],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [18]]),
  ('regression: recursive factorial',
   ([['push', 2],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [2]]),
  ('recursion depth exactly at the limit',
   ([['push', 2],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    4,
    500),
   ['halt', [2]]),
  ('recursion one frame over the limit',
   ([['push', 2],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    3,
    500),
   ['StackOverflowError', 3]),
  ('control: fuel exhaustion',
   ([['push', 2],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])],
 [('two-argument call binds first argument to slot 0',
   ([['push', 24], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [21]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 11], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']],
    10,
    100),
   ['halt', [6]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 4],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [28]]),
  ('regression: recursive factorial',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [6]]),
  ('recursion depth exactly at the limit',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    5,
    500),
   ['halt', [6]]),
  ('recursion one frame over the limit',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    4,
    500),
   ['StackOverflowError', 4]),
  ('control: fuel exhaustion',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])],
 [('two-argument call binds first argument to slot 0',
   ([['push', 25], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [22]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 12], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']],
    10,
    100),
   ['halt', [7]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 5],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [40]]),
  ('regression: recursive factorial',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [24]]),
  ('recursion depth exactly at the limit',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    6,
    500),
   ['halt', [24]]),
  ('recursion one frame over the limit',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    5,
    500),
   ['StackOverflowError', 5]),
  ('control: fuel exhaustion',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code, max_depth, fuel):
    def run():
        frames = [{'locals': [0] * 4, 'stack': [], 'ret': None}]
        pc = 0
        for _ in range(fuel):
            f = frames[-1]
            ins = code[pc]
            op = ins[0]
            if op == 'push':
                f['stack'].append(ins[1])
                pc += 1
            elif op == 'load':
                f['stack'].append(f['locals'][ins[1]])
                pc += 1
            elif op == 'store':
                f['locals'][ins[1]] = f['stack'].pop()
                pc += 1
            elif op in ('add', 'sub', 'mul'):
                b = f['stack'].pop()
                a = f['stack'].pop()
                f['stack'].append(a + b if op == 'add' else a - b if op == 'sub' else a * b)
                pc += 1
            elif op == 'jz':
                pc = ins[1] if f['stack'].pop() == 0 else pc + 1
            elif op == 'jmp':
                pc = ins[1]
            elif op == 'call':
                target, nargs, nlocals = ins[1], ins[2], ins[3]
                if len(frames) >= max_depth:
                    return ['StackOverflowError', len(frames)]
                args = f['stack'][len(f['stack']) - nargs:]
                f['stack'] = f['stack'][:-nargs]
                frames.append({'locals': args + [0] * (nlocals - nargs), 'stack': [], 'ret': pc + 1})
                pc = target
            elif op == 'ret':
                value = f['stack'].pop()
                frames.pop()
                frames[-1]['stack'].append(value)
                pc = f['ret']
            else:
                return ['halt', f['stack']]
        return ['fuel', pc]
    try:
        return run()
    except (IndexError, TypeError):
        return ['vm-fault']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('two-argument call binds first argument to slot 0',
   ([['push', 21], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [18]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 8], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']], 10, 100),
   ['halt', [3]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 1],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [4]]),
  ('regression: recursive factorial',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [6]]),
  ('recursion depth exactly at the limit',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    5,
    500),
   ['halt', [6]]),
  ('recursion one frame over the limit',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    4,
    500),
   ['StackOverflowError', 4]),
  ('control: fuel exhaustion',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])],
 [('two-argument call binds first argument to slot 0',
   ([['push', 22], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [19]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 9], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']], 10, 100),
   ['halt', [4]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 2],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [10]]),
  ('regression: recursive factorial',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [24]]),
  ('recursion depth exactly at the limit',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    6,
    500),
   ['halt', [24]]),
  ('recursion one frame over the limit',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    5,
    500),
   ['StackOverflowError', 5]),
  ('control: fuel exhaustion',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])],
 [('two-argument call binds first argument to slot 0',
   ([['push', 23], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [20]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 10], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']],
    10,
    100),
   ['halt', [5]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 3],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [18]]),
  ('regression: recursive factorial',
   ([['push', 2],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [2]]),
  ('recursion depth exactly at the limit',
   ([['push', 2],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    4,
    500),
   ['halt', [2]]),
  ('recursion one frame over the limit',
   ([['push', 2],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    3,
    500),
   ['StackOverflowError', 3]),
  ('control: fuel exhaustion',
   ([['push', 2],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])],
 [('two-argument call binds first argument to slot 0',
   ([['push', 24], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [21]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 11], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']],
    10,
    100),
   ['halt', [6]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 4],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [28]]),
  ('regression: recursive factorial',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [6]]),
  ('recursion depth exactly at the limit',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    5,
    500),
   ['halt', [6]]),
  ('recursion one frame over the limit',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    4,
    500),
   ['StackOverflowError', 4]),
  ('control: fuel exhaustion',
   ([['push', 3],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])],
 [('two-argument call binds first argument to slot 0',
   ([['push', 25], ['push', 3], ['call', 4, 2, 2], ['halt'], ['load', 0], ['load', 1], ['sub'], ['ret']],
    10,
    100),
   ['halt', [22]]),
  ('zero-argument call keeps caller operand stack',
   ([['push', 12], ['call', 4, 0, 1], ['sub'], ['halt'], ['load', 0], ['push', 5], ['add'], ['ret']],
    10,
    100),
   ['halt', [7]]),
  ('extra locals are zero-initialised after arguments',
   ([['push', 5],
     ['call', 3, 1, 2],
     ['halt'],
     ['load', 0],
     ['push', 3],
     ['add'],
     ['store', 1],
     ['load', 1],
     ['load', 0],
     ['mul'],
     ['ret']],
    10,
    100),
   ['halt', [40]]),
  ('regression: recursive factorial',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    500),
   ['halt', [24]]),
  ('recursion depth exactly at the limit',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    6,
    500),
   ['halt', [24]]),
  ('recursion one frame over the limit',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    5,
    500),
   ['StackOverflowError', 5]),
  ('control: fuel exhaustion',
   ([['push', 4],
     ['call', 3, 1, 1],
     ['halt'],
     ['load', 0],
     ['jz', 12],
     ['load', 0],
     ['load', 0],
     ['push', 1],
     ['sub'],
     ['call', 3, 1, 1],
     ['mul'],
     ['ret'],
     ['push', 1],
     ['ret']],
    20,
    3),
   ['fuel', 4])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
After calling a function with no arguments the caller loses all pending operands and faults.

Instructions: push v, load k, store k, add/sub/mul (second-from-top op top), jz t, jmp t, call t nargs nlocals, ret, halt. call pops nargs values (the first pushed becomes local 0), appends zero locals up to nlocals, records return pc = call pc + 1, and raises ["StackOverflowError", frames] when the frame count already equals max_depth. ret pops the result, discards the callee frame, pushes the result on the caller stack and resumes at the saved pc. Each executed instruction costs one fuel; running out returns ["fuel", pc]; host faults are ["vm-fault"].

split: open-access