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

N = 1
observations = []
def solve(*args):
    code = args[0]
    def b(k):
        return code[k] if k < len(code) else 0
    i = 0
    lens = []
    while i < len(code):
        start = i
        osz = 4
        asz = 4
        while b(i) in (0x66, 0x67, 0xF0, 0xF2, 0xF3):
            if b(i) == 0x66: asz = 2
            if b(i) == 0x67: asz = 2
            i += 1
        op = b(i)
        i += 1
        if op == 0x0F:
            op = 0x0F00 | b(i)
            i += 1
        modrm = op in (0x01, 0x03, 0x89, 0x8B, 0x81, 0x83, 0x0FAF)
        imm = {0x81: osz, 0x83: 1, 0xE8: osz, 0xEB: 1, 0x0F84: osz}.get(op, osz if 0xB8 <= op <= 0xBF else 0)
        if modrm:
            m = b(i)
            i += 1
            mod, rm = m >> 6, m & 7
            if mod != 3:
                if asz == 2:
                    i += 2 if (mod == 0 and rm == 6) or mod == 2 else mod
                else:
                    if rm == 4:
                        base = b(i) & 7
                        i += 1
                        if mod == 0 and base == 5:
                            i += 4
                    i += 4 if (mod == 0 and rm == 5) or mod == 2 else mod
        i += imm
        lens.append(i - start)
    return lens
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144]], [1, 2, 3, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195]], [3, 4, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144]], [1, 2, 3, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195]], [3, 4, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195]], [3, 4, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])]]
for label, args, expected in fixtures[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(*args):
    code = args[0]
    def b(k):
        return code[k] if k < len(code) else 0
    i = 0
    lens = []
    while i < len(code):
        start = i
        osz = 4
        asz = 4
        while b(i) in (0x66, 0x67, 0xF0, 0xF2, 0xF3):
            if b(i) == 0x66 and i == start: osz = 2
            if b(i) == 0x67: asz = 2
            i += 1
        op = b(i)
        i += 1
        if op == 0x0F:
            op = 0x0F00 | b(i)
            i += 1
        modrm = op in (0x01, 0x03, 0x89, 0x8B, 0x81, 0x83, 0x0FAF)
        imm = {0x81: osz, 0x83: 1, 0xE8: osz, 0xEB: 1, 0x0F84: osz}.get(op, osz if 0xB8 <= op <= 0xBF else 0)
        if modrm:
            m = b(i)
            i += 1
            mod, rm = m >> 6, m & 7
            if mod != 3:
                if asz == 2:
                    i += 2 if (mod == 0 and rm == 6) or mod == 2 else mod
                else:
                    if rm == 4:
                        base = b(i) & 7
                        i += 1
                        if mod == 0 and base == 5:
                            i += 4
                    i += 4 if (mod == 0 and rm == 5) or mod == 2 else mod
        i += imm
        lens.append(i - start)
    return lens
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144]], [1, 2, 3, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195]], [3, 4, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144]], [1, 2, 3, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195]], [3, 4, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195]], [3, 4, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])]]
for label, args, expected in fixtures[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:
Immediates after a 0x66 prefix are decoded as 4 bytes.

Input [code]: a byte list decoded as a toy x86-like ISA. Prefixes 0x66 (operand size 16), 0x67 (address size 16), 0xF0/0xF2/0xF3 in any order. 0x0F escapes to a two-byte opcode. ModRM follows 01/03/89/8B/81/83/0F AF. Immediates: 81, B8-BF, E8, 0F 84 take the operand size (2 or 4 bytes); 83 and EB take 1. 32-bit ModRM: mod 3 none; rm 4 adds a SIB byte and a SIB base of 5 with mod 0 adds disp32; mod 0 rm 5 adds disp32; mod 1 disp8; mod 2 disp32. 16-bit ModRM: mod 0 rm 6 or mod 2 add disp16, mod 1 disp8, no SIB. Return the length of each instruction.

split: open-access


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

N = 1
observations = []
def solve(*args):
    code = args[0]
    def b(k):
        return code[k] if k < len(code) else 0
    i = 0
    lens = []
    while i < len(code):
        start = i
        osz = 4
        asz = 4
        while b(i) in (0x66, 0x67, 0xF0, 0xF2, 0xF3):
            if b(i) == 0x66: osz = 2
            if b(i) == 0x67: asz = 2
            i += 1
        op = b(i)
        i += 1
        if op == 0x0F:
            op = 0x0F00 | b(i)
            i += 1
        modrm = op in (0x01, 0x03, 0x89, 0x8B, 0x81, 0x83, 0x0FAF)
        imm = {0x81: osz, 0x83: osz, 0xE8: osz, 0xEB: 1, 0x0F84: osz}.get(op, osz if 0xB8 <= op <= 0xBF else 0)
        if modrm:
            m = b(i)
            i += 1
            mod, rm = m >> 6, m & 7
            if mod != 3:
                if asz == 2:
                    i += 2 if (mod == 0 and rm == 6) or mod == 2 else mod
                else:
                    if rm == 4:
                        base = b(i) & 7
                        i += 1
                        if mod == 0 and base == 5:
                            i += 4
                    i += 4 if (mod == 0 and rm == 5) or mod == 2 else mod
        i += imm
        lens.append(i - start)
    return lens
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144]], [1, 2, 3, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195]], [3, 4, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144]], [1, 2, 3, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195]], [3, 4, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195]], [3, 4, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])]]
for label, args, expected in fixtures[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(*args):
    code = args[0]
    def b(k):
        return code[k] if k < len(code) else 0
    i = 0
    lens = []
    while i < len(code):
        start = i
        osz = 4
        asz = 4
        while b(i) in (0x66, 0x67, 0xF0, 0xF2, 0xF3):
            if b(i) == 0x66: osz = 2
            if b(i) == 0x67: asz = 2
            i += 1
        op = b(i)
        i += 1
        if op == 0x0F:
            op = 0x0F00 | b(i)
            i += 1
        modrm = op in (0x01, 0x03, 0x89, 0x8B, 0x81, 0x83, 0x0FAF)
        imm = {0x81: osz, 0x83: 2, 0xE8: osz, 0xEB: 1, 0x0F84: osz}.get(op, osz if 0xB8 <= op <= 0xBF else 0)
        if modrm:
            m = b(i)
            i += 1
            mod, rm = m >> 6, m & 7
            if mod != 3:
                if asz == 2:
                    i += 2 if (mod == 0 and rm == 6) or mod == 2 else mod
                else:
                    if rm == 4:
                        base = b(i) & 7
                        i += 1
                        if mod == 0 and base == 5:
                            i += 4
                    i += 4 if (mod == 0 and rm == 5) or mod == 2 else mod
        i += imm
        lens.append(i - start)
    return lens
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144]], [1, 2, 3, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195]], [3, 4, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144]], [1, 2, 3, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195]], [3, 4, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195]], [3, 4, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])]]
for label, args, expected in fixtures[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:
Opcode 0x83 swallows three extra bytes.

Input [code]: a byte list decoded as a toy x86-like ISA. Prefixes 0x66 (operand size 16), 0x67 (address size 16), 0xF0/0xF2/0xF3 in any order. 0x0F escapes to a two-byte opcode. ModRM follows 01/03/89/8B/81/83/0F AF. Immediates: 81, B8-BF, E8, 0F 84 take the operand size (2 or 4 bytes); 83 and EB take 1. 32-bit ModRM: mod 3 none; rm 4 adds a SIB byte and a SIB base of 5 with mod 0 adds disp32; mod 0 rm 5 adds disp32; mod 1 disp8; mod 2 disp32. 16-bit ModRM: mod 0 rm 6 or mod 2 add disp16, mod 1 disp8, no SIB. Return the length of each instruction.

split: open-access


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

N = 1
observations = []
def solve(*args):
    code = args[0]
    def b(k):
        return code[k] if k < len(code) else 0
    i = 0
    lens = []
    while i < len(code):
        start = i
        osz = 4
        asz = 4
        while b(i) in (0x66, 0x67, 0xF0, 0xF2, 0xF3):
            if b(i) == 0x66: osz = 2
            if b(i) == 0x67: asz = 2
            i += 1
        op = b(i)
        i += 1
        if op == 0x0F:
            op = 0x0F00 | b(i)
            i += 1
        modrm = op in (0x01, 0x03, 0x89, 0x8B, 0x81, 0x83, 0x0FAF)
        imm = {0x81: osz, 0x83: 1, 0xE8: osz, 0xEB: 1, 0x0F84: osz}.get(op, osz if 0xB8 <= op <= 0xBF else 0)
        if modrm:
            m = b(i)
            i += 1
            mod, rm = m >> 6, m & 7
            if mod != 3:
                if False:
                    i += 2 if (mod == 0 and rm == 6) or mod == 2 else mod
                else:
                    if rm == 4:
                        base = b(i) & 7
                        i += 1
                        if mod == 0 and base == 5:
                            i += 4
                    i += 4 if (mod == 0 and rm == 5) or mod == 2 else mod
        i += imm
        lens.append(i - start)
    return lens
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144]], [1, 2, 3, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195]], [3, 4, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144]], [1, 2, 3, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195]], [3, 4, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195]], [3, 4, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])]]
for label, args, expected in fixtures[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(*args):
    code = args[0]
    def b(k):
        return code[k] if k < len(code) else 0
    i = 0
    lens = []
    while i < len(code):
        start = i
        osz = 4
        asz = 4
        while b(i) in (0x66, 0x67, 0xF0, 0xF2, 0xF3):
            if b(i) == 0x66: osz = 2
            if b(i) == 0x67: asz = 2
            i += 1
        op = b(i)
        i += 1
        if op == 0x0F:
            op = 0x0F00 | b(i)
            i += 1
        modrm = op in (0x01, 0x03, 0x89, 0x8B, 0x81, 0x83, 0x0FAF)
        imm = {0x81: osz, 0x83: 1, 0xE8: osz, 0xEB: 1, 0x0F84: osz}.get(op, osz if 0xB8 <= op <= 0xBF else 0)
        if modrm:
            m = b(i)
            i += 1
            mod, rm = m >> 6, m & 7
            if mod != 3:
                if asz == 2 and mod != 0:
                    i += 2 if (mod == 0 and rm == 6) or mod == 2 else mod
                else:
                    if rm == 4:
                        base = b(i) & 7
                        i += 1
                        if mod == 0 and base == 5:
                            i += 4
                    i += 4 if (mod == 0 and rm == 5) or mod == 2 else mod
        i += imm
        lens.append(i - start)
    return lens
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144]], [1, 2, 3, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195]], [3, 4, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144]], [1, 2, 3, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195]], [3, 4, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195]], [3, 4, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])]]
for label, args, expected in fixtures[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:
ModRM operands under the 0x67 prefix get SIB and disp32 lengths.

Input [code]: a byte list decoded as a toy x86-like ISA. Prefixes 0x66 (operand size 16), 0x67 (address size 16), 0xF0/0xF2/0xF3 in any order. 0x0F escapes to a two-byte opcode. ModRM follows 01/03/89/8B/81/83/0F AF. Immediates: 81, B8-BF, E8, 0F 84 take the operand size (2 or 4 bytes); 83 and EB take 1. 32-bit ModRM: mod 3 none; rm 4 adds a SIB byte and a SIB base of 5 with mod 0 adds disp32; mod 0 rm 5 adds disp32; mod 1 disp8; mod 2 disp32. 16-bit ModRM: mod 0 rm 6 or mod 2 add disp16, mod 1 disp8, no SIB. Return the length of each instruction.

split: open-access


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

N = 1
observations = []
def solve(*args):
    code = args[0]
    def b(k):
        return code[k] if k < len(code) else 0
    i = 0
    lens = []
    while i < len(code):
        start = i
        osz = 4
        asz = 4
        while b(i) in (0x66, 0x67, 0xF0, 0xF2, 0xF3):
            if b(i) == 0x66: osz = 2
            if b(i) == 0x67: asz = 2
            i += 1
        op = b(i)
        i += 1
        if op == 0x0F:
            op = 0x0F00 | b(i)
        modrm = op in (0x01, 0x03, 0x89, 0x8B, 0x81, 0x83, 0x0FAF)
        imm = {0x81: osz, 0x83: 1, 0xE8: osz, 0xEB: 1, 0x0F84: osz}.get(op, osz if 0xB8 <= op <= 0xBF else 0)
        if modrm:
            m = b(i)
            i += 1
            mod, rm = m >> 6, m & 7
            if mod != 3:
                if asz == 2:
                    i += 2 if (mod == 0 and rm == 6) or mod == 2 else mod
                else:
                    if rm == 4:
                        base = b(i) & 7
                        i += 1
                        if mod == 0 and base == 5:
                            i += 4
                    i += 4 if (mod == 0 and rm == 5) or mod == 2 else mod
        i += imm
        lens.append(i - start)
    return lens
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144]], [1, 2, 3, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195]], [3, 4, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144]], [1, 2, 3, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195]], [3, 4, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195]], [3, 4, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])]]
for label, args, expected in fixtures[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(*args):
    code = args[0]
    def b(k):
        return code[k] if k < len(code) else 0
    i = 0
    lens = []
    while i < len(code):
        start = i
        osz = 4
        asz = 4
        while b(i) in (0x66, 0x67, 0xF0, 0xF2, 0xF3):
            if b(i) == 0x66: osz = 2
            if b(i) == 0x67: asz = 2
            i += 1
        op = b(i)
        i += 1
        if op == 0x0F:
            op = b(i)
            i += 1
        modrm = op in (0x01, 0x03, 0x89, 0x8B, 0x81, 0x83, 0x0FAF)
        imm = {0x81: osz, 0x83: 1, 0xE8: osz, 0xEB: 1, 0x0F84: osz}.get(op, osz if 0xB8 <= op <= 0xBF else 0)
        if modrm:
            m = b(i)
            i += 1
            mod, rm = m >> 6, m & 7
            if mod != 3:
                if asz == 2:
                    i += 2 if (mod == 0 and rm == 6) or mod == 2 else mod
                else:
                    if rm == 4:
                        base = b(i) & 7
                        i += 1
                        if mod == 0 and base == 5:
                            i += 4
                    i += 4 if (mod == 0 and rm == 5) or mod == 2 else mod
        i += imm
        lens.append(i - start)
    return lens
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144]], [1, 2, 3, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195]], [3, 4, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144]], [1, 2, 3, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195]], [3, 4, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195]], [3, 4, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])]]
for label, args, expected in fixtures[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-byte opcodes are one byte short and the second opcode byte is read as ModRM.

Input [code]: a byte list decoded as a toy x86-like ISA. Prefixes 0x66 (operand size 16), 0x67 (address size 16), 0xF0/0xF2/0xF3 in any order. 0x0F escapes to a two-byte opcode. ModRM follows 01/03/89/8B/81/83/0F AF. Immediates: 81, B8-BF, E8, 0F 84 take the operand size (2 or 4 bytes); 83 and EB take 1. 32-bit ModRM: mod 3 none; rm 4 adds a SIB byte and a SIB base of 5 with mod 0 adds disp32; mod 0 rm 5 adds disp32; mod 1 disp8; mod 2 disp32. 16-bit ModRM: mod 0 rm 6 or mod 2 add disp16, mod 1 disp8, no SIB. Return the length of each instruction.

split: open-access


prompt:
A low digit sum that only exceeds 15 because of the carry-in is not adjusted.

Input [xs, ys, c]: little-endian packed-BCD byte lists and a carry-in. For each byte: s = a+b+c; AF = low-nibble sum (with carry) > 0x0F; CF = s > 0xFF; al = s & 0xFF. Decimal adjust: if (al & 0x0F) > 9 or AF then al += 6 (8-bit wrap); then if the pre-adjust al > 0x99 or CF then al += 0x60 (8-bit wrap) and carry-out = 1, else carry-out = 0. The carry-out feeds the next byte. Return [result bytes, final carry].

split: open-access


prompt:
A low-digit adjust that pushes the byte past 0x99 triggers a spurious +0x60.

Input [xs, ys, c]: little-endian packed-BCD byte lists and a carry-in. For each byte: s = a+b+c; AF = low-nibble sum (with carry) > 0x0F; CF = s > 0xFF; al = s & 0xFF. Decimal adjust: if (al & 0x0F) > 9 or AF then al += 6 (8-bit wrap); then if the pre-adjust al > 0x99 or CF then al += 0x60 (8-bit wrap) and carry-out = 1, else carry-out = 0. The carry-out feeds the next byte. Return [result bytes, final carry].

split: open-access


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

N = 1
observations = []
def solve(*args):
    xs, ys, c = args
    out = []
    for a, b in zip(xs, ys):
        s = a + b + c
        af = int((a & 0x0F) + (b & 0x0F) + c > 0x0F)
        cf = int(s > 0xFF)
        al = s & 0xFF
        old_al, old_cf = al, cf
        if (al & 0x0F) > 9 or af:
            al = (al + 6) & 0xFF
        if old_al > 0x99 or old_cf:
            c = int(al + 0x60 > 0xFF)
            al = (al + 0x60) & 0xFF
        else:
            c = 0
        out.append(al)
    return [out, c]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('digits without adjust', [[18, 52], [33, 67], 0], [[51, 119], 0]), ('low digit overflow', [[24, 0], [8, 0], 0], [[38, 0], 0]), ('half carry without low digit above nine', [[9, 16], [9, 0], 0], [[24, 16], 0]), ('carry-in feeds half carry', [[24, 0], [7, 0], 1], [[38, 0], 0]), ('high digit overflow and carry out', [[144, 85], [48, 68], 0], [[32, 0], 1]), ('low adjust pushes high digit', [[149, 0], [5, 0], 0], [[0, 1], 0]), ('binary carry from high digits', [[153, 153], [153, 1], 0], [[152, 1], 1]), ('carry chains across bytes', [[153, 9, 0], [1, 0, 0], 1], [[1, 16, 0], 0]), ('non-decimal low digit', [[143, 0], [7, 2], 0], [[156, 2], 0]), ('high digit exactly A', [[80, 1], [74, 0], 0], [[0, 2], 0])], [('digits without adjust', [[18, 52], [33, 67], 0], [[51, 119], 0]), ('low digit overflow', [[25, 0], [8, 0], 0], [[39, 0], 0]), ('half carry without low digit above nine', [[9, 16], [9, 0], 0], [[24, 16], 0]), ('carry-in feeds half carry', [[40, 0], [7, 0], 1], [[54, 0], 0]), ('high digit overflow and carry out', [[144, 85], [64, 68], 0], [[48, 0], 1]), ('low adjust pushes high digit', [[149, 0], [5, 0], 0], [[0, 1], 0]), ('binary carry from high digits', [[153, 153], [153, 2], 0], [[152, 2], 1]), ('carry chains across bytes', [[153, 9, 0], [1, 0, 0], 1], [[1, 16, 0], 0]), ('non-decimal low digit', [[143, 0], [7, 3], 0], [[156, 3], 0]), ('high digit exactly A', [[80, 1], [74, 0], 0], [[0, 2], 0])], [('digits without adjust', [[18, 52], [33, 67], 0], [[51, 119], 0]), ('low digit overflow', [[24, 0], [8, 0], 0], [[38, 0], 0]), ('half carry without low digit above nine', [[9, 16], [9, 0], 0], [[24, 16], 0]), ('carry-in feeds half carry', [[8, 0], [7, 0], 1], [[22, 0], 0]), ('high digit overflow and carry out', [[144, 85], [32, 68], 0], [[16, 0], 1]), ('low adjust pushes high digit', [[149, 0], [5, 0], 0], [[0, 1], 0]), ('binary carry from high digits', [[153, 153], [153, 3], 0], [[152, 3], 1]), ('carry chains across bytes', [[153, 9, 0], [1, 0, 0], 1], [[1, 16, 0], 0]), ('non-decimal low digit', [[143, 0], [7, 4], 0], [[156, 4], 0]), ('high digit exactly A', [[80, 1], [74, 0], 0], [[0, 2], 0])], [('digits without adjust', [[18, 52], [33, 67], 0], [[51, 119], 0]), ('low digit overflow', [[25, 0], [8, 0], 0], [[39, 0], 0]), ('half carry without low digit above nine', [[9, 16], [9, 0], 0], [[24, 16], 0]), ('carry-in feeds half carry', [[24, 0], [7, 0], 1], [[38, 0], 0]), ('high digit overflow and carry out', [[144, 85], [48, 68], 0], [[32, 0], 1]), ('low adjust pushes high digit', [[149, 0], [5, 0], 0], [[0, 1], 0]), ('binary carry from high digits', [[153, 153], [153, 4], 0], [[152, 4], 1]), ('carry chains across bytes', [[153, 9, 0], [1, 0, 0], 1], [[1, 16, 0], 0]), ('non-decimal low digit', [[143, 0], [7, 5], 0], [[156, 5], 0]), ('high digit exactly A', [[80, 1], [74, 0], 0], [[0, 2], 0])], [('digits without adjust', [[18, 52], [33, 67], 0], [[51, 119], 0]), ('low digit overflow', [[24, 0], [8, 0], 0], [[38, 0], 0]), ('half carry without low digit above nine', [[9, 16], [9, 0], 0], [[24, 16], 0]), ('carry-in feeds half carry', [[40, 0], [7, 0], 1], [[54, 0], 0]), ('high digit overflow and carry out', [[144, 85], [64, 68], 0], [[48, 0], 1]), ('low adjust pushes high digit', [[149, 0], [5, 0], 0], [[0, 1], 0]), ('binary carry from high digits', [[153, 153], [153, 5], 0], [[152, 5], 1]), ('carry chains across bytes', [[153, 9, 0], [1, 0, 0], 1], [[1, 16, 0], 0]), ('non-decimal low digit', [[143, 0], [7, 6], 0], [[156, 6], 0]), ('high digit exactly A', [[80, 1], [74, 0], 0], [[0, 2], 0])]]
for label, args, expected in fixtures[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(*args):
    xs, ys, c = args
    out = []
    for a, b in zip(xs, ys):
        s = a + b + c
        af = int((a & 0x0F) + (b & 0x0F) + c > 0x0F)
        cf = int(s > 0xFF)
        al = s & 0xFF
        old_al, old_cf = al, cf
        if (al & 0x0F) > 9 or af:
            al = (al + 6) & 0xFF
        if old_al > 0x99 or old_cf:
            al = (al + 0x60) & 0xFF
            c = old_cf
        else:
            c = 0
        out.append(al)
    return [out, c]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('digits without adjust', [[18, 52], [33, 67], 0], [[51, 119], 0]), ('low digit overflow', [[24, 0], [8, 0], 0], [[38, 0], 0]), ('half carry without low digit above nine', [[9, 16], [9, 0], 0], [[24, 16], 0]), ('carry-in feeds half carry', [[24, 0], [7, 0], 1], [[38, 0], 0]), ('high digit overflow and carry out', [[144, 85], [48, 68], 0], [[32, 0], 1]), ('low adjust pushes high digit', [[149, 0], [5, 0], 0], [[0, 1], 0]), ('binary carry from high digits', [[153, 153], [153, 1], 0], [[152, 1], 1]), ('carry chains across bytes', [[153, 9, 0], [1, 0, 0], 1], [[1, 16, 0], 0]), ('non-decimal low digit', [[143, 0], [7, 2], 0], [[156, 2], 0]), ('high digit exactly A', [[80, 1], [74, 0], 0], [[0, 2], 0])], [('digits without adjust', [[18, 52], [33, 67], 0], [[51, 119], 0]), ('low digit overflow', [[25, 0], [8, 0], 0], [[39, 0], 0]), ('half carry without low digit above nine', [[9, 16], [9, 0], 0], [[24, 16], 0]), ('carry-in feeds half carry', [[40, 0], [7, 0], 1], [[54, 0], 0]), ('high digit overflow and carry out', [[144, 85], [64, 68], 0], [[48, 0], 1]), ('low adjust pushes high digit', [[149, 0], [5, 0], 0], [[0, 1], 0]), ('binary carry from high digits', [[153, 153], [153, 2], 0], [[152, 2], 1]), ('carry chains across bytes', [[153, 9, 0], [1, 0, 0], 1], [[1, 16, 0], 0]), ('non-decimal low digit', [[143, 0], [7, 3], 0], [[156, 3], 0]), ('high digit exactly A', [[80, 1], [74, 0], 0], [[0, 2], 0])], [('digits without adjust', [[18, 52], [33, 67], 0], [[51, 119], 0]), ('low digit overflow', [[24, 0], [8, 0], 0], [[38, 0], 0]), ('half carry without low digit above nine', [[9, 16], [9, 0], 0], [[24, 16], 0]), ('carry-in feeds half carry', [[8, 0], [7, 0], 1], [[22, 0], 0]), ('high digit overflow and carry out', [[144, 85], [32, 68], 0], [[16, 0], 1]), ('low adjust pushes high digit', [[149, 0], [5, 0], 0], [[0, 1], 0]), ('binary carry from high digits', [[153, 153], [153, 3], 0], [[152, 3], 1]), ('carry chains across bytes', [[153, 9, 0], [1, 0, 0], 1], [[1, 16, 0], 0]), ('non-decimal low digit', [[143, 0], [7, 4], 0], [[156, 4], 0]), ('high digit exactly A', [[80, 1], [74, 0], 0], [[0, 2], 0])], [('digits without adjust', [[18, 52], [33, 67], 0], [[51, 119], 0]), ('low digit overflow', [[25, 0], [8, 0], 0], [[39, 0], 0]), ('half carry without low digit above nine', [[9, 16], [9, 0], 0], [[24, 16], 0]), ('carry-in feeds half carry', [[24, 0], [7, 0], 1], [[38, 0], 0]), ('high digit overflow and carry out', [[144, 85], [48, 68], 0], [[32, 0], 1]), ('low adjust pushes high digit', [[149, 0], [5, 0], 0], [[0, 1], 0]), ('binary carry from high digits', [[153, 153], [153, 4], 0], [[152, 4], 1]), ('carry chains across bytes', [[153, 9, 0], [1, 0, 0], 1], [[1, 16, 0], 0]), ('non-decimal low digit', [[143, 0], [7, 5], 0], [[156, 5], 0]), ('high digit exactly A', [[80, 1], [74, 0], 0], [[0, 2], 0])], [('digits without adjust', [[18, 52], [33, 67], 0], [[51, 119], 0]), ('low digit overflow', [[24, 0], [8, 0], 0], [[38, 0], 0]), ('half carry without low digit above nine', [[9, 16], [9, 0], 0], [[24, 16], 0]), ('carry-in feeds half carry', [[40, 0], [7, 0], 1], [[54, 0], 0]), ('high digit overflow and carry out', [[144, 85], [64, 68], 0], [[48, 0], 1]), ('low adjust pushes high digit', [[149, 0], [5, 0], 0], [[0, 1], 0]), ('binary carry from high digits', [[153, 153], [153, 5], 0], [[152, 5], 1]), ('carry chains across bytes', [[153, 9, 0], [1, 0, 0], 1], [[1, 16, 0], 0]), ('non-decimal low digit', [[143, 0], [7, 6], 0], [[156, 6], 0]), ('high digit exactly A', [[80, 1], [74, 0], 0], [[0, 2], 0])]]
for label, args, expected in fixtures[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 high-digit adjust that stays below 0x100 loses the decimal carry.

Input [xs, ys, c]: little-endian packed-BCD byte lists and a carry-in. For each byte: s = a+b+c; AF = low-nibble sum (with carry) > 0x0F; CF = s > 0xFF; al = s & 0xFF. Decimal adjust: if (al & 0x0F) > 9 or AF then al += 6 (8-bit wrap); then if the pre-adjust al > 0x99 or CF then al += 0x60 (8-bit wrap) and carry-out = 1, else carry-out = 0. The carry-out feeds the next byte. Return [result bytes, final carry].

split: open-access


prompt:
0x09 + 0x09 yields 0x12 instead of 0x18.

Input [xs, ys, c]: little-endian packed-BCD byte lists and a carry-in. For each byte: s = a+b+c; AF = low-nibble sum (with carry) > 0x0F; CF = s > 0xFF; al = s & 0xFF. Decimal adjust: if (al & 0x0F) > 9 or AF then al += 6 (8-bit wrap); then if the pre-adjust al > 0x99 or CF then al += 0x60 (8-bit wrap) and carry-out = 1, else carry-out = 0. The carry-out feeds the next byte. Return [result bytes, final carry].

split: open-access


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

N = 1
observations = []
def solve(*args):
    xs, ys, c = args
    out = []
    for a, b in zip(xs, ys):
        s = a + b + (c if out else 0)
        af = int((a & 0x0F) + (b & 0x0F) + c > 0x0F)
        cf = int(s > 0xFF)
        al = s & 0xFF
        old_al, old_cf = al, cf
        if (al & 0x0F) > 9 or af:
            al = (al + 6) & 0xFF
        if old_al > 0x99 or old_cf:
            al = (al + 0x60) & 0xFF
            c = 1
        else:
            c = 0
        out.append(al)
    return [out, c]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('digits without adjust', [[18, 52], [33, 67], 0], [[51, 119], 0]), ('low digit overflow', [[24, 0], [8, 0], 0], [[38, 0], 0]), ('half carry without low digit above nine', [[9, 16], [9, 0], 0], [[24, 16], 0]), ('carry-in feeds half carry', [[24, 0], [7, 0], 1], [[38, 0], 0]), ('high digit overflow and carry out', [[144, 85], [48, 68], 0], [[32, 0], 1]), ('low adjust pushes high digit', [[149, 0], [5, 0], 0], [[0, 1], 0]), ('binary carry from high digits', [[153, 153], [153, 1], 0], [[152, 1], 1]), ('carry chains across bytes', [[153, 9, 0], [1, 0, 0], 1], [[1, 16, 0], 0]), ('non-decimal low digit', [[143, 0], [7, 2], 0], [[156, 2], 0]), ('high digit exactly A', [[80, 1], [74, 0], 0], [[0, 2], 0])], [('digits without adjust', [[18, 52], [33, 67], 0], [[51, 119], 0]), ('low digit overflow', [[25, 0], [8, 0], 0], [[39, 0], 0]), ('half carry without low digit above nine', [[9, 16], [9, 0], 0], [[24, 16], 0]), ('carry-in feeds half carry', [[40, 0], [7, 0], 1], [[54, 0], 0]), ('high digit overflow and carry out', [[144, 85], [64, 68], 0], [[48, 0], 1]), ('low adjust pushes high digit', [[149, 0], [5, 0], 0], [[0, 1], 0]), ('binary carry from high digits', [[153, 153], [153, 2], 0], [[152, 2], 1]), ('carry chains across bytes', [[153, 9, 0], [1, 0, 0], 1], [[1, 16, 0], 0]), ('non-decimal low digit', [[143, 0], [7, 3], 0], [[156, 3], 0]), ('high digit exactly A', [[80, 1], [74, 0], 0], [[0, 2], 0])], [('digits without adjust', [[18, 52], [33, 67], 0], [[51, 119], 0]), ('low digit overflow', [[24, 0], [8, 0], 0], [[38, 0], 0]), ('half carry without low digit above nine', [[9, 16], [9, 0], 0], [[24, 16], 0]), ('carry-in feeds half carry', [[8, 0], [7, 0], 1], [[22, 0], 0]), ('high digit overflow and carry out', [[144, 85], [32, 68], 0], [[16, 0], 1]), ('low adjust pushes high digit', [[149, 0], [5, 0], 0], [[0, 1], 0]), ('binary carry from high digits', [[153, 153], [153, 3], 0], [[152, 3], 1]), ('carry chains across bytes', [[153, 9, 0], [1, 0, 0], 1], [[1, 16, 0], 0]), ('non-decimal low digit', [[143, 0], [7, 4], 0], [[156, 4], 0]), ('high digit exactly A', [[80, 1], [74, 0], 0], [[0, 2], 0])], [('digits without adjust', [[18, 52], [33, 67], 0], [[51, 119], 0]), ('low digit overflow', [[25, 0], [8, 0], 0], [[39, 0], 0]), ('half carry without low digit above nine', [[9, 16], [9, 0], 0], [[24, 16], 0]), ('carry-in feeds half carry', [[24, 0], [7, 0], 1], [[38, 0], 0]), ('high digit overflow and carry out', [[144, 85], [48, 68], 0], [[32, 0], 1]), ('low adjust pushes high digit', [[149, 0], [5, 0], 0], [[0, 1], 0]), ('binary carry from high digits', [[153, 153], [153, 4], 0], [[152, 4], 1]), ('carry chains across bytes', [[153, 9, 0], [1, 0, 0], 1], [[1, 16, 0], 0]), ('non-decimal low digit', [[143, 0], [7, 5], 0], [[156, 5], 0]), ('high digit exactly A', [[80, 1], [74, 0], 0], [[0, 2], 0])], [('digits without adjust', [[18, 52], [33, 67], 0], [[51, 119], 0]), ('low digit overflow', [[24, 0], [8, 0], 0], [[38, 0], 0]), ('half carry without low digit above nine', [[9, 16], [9, 0], 0], [[24, 16], 0]), ('carry-in feeds half carry', [[40, 0], [7, 0], 1], [[54, 0], 0]), ('high digit overflow and carry out', [[144, 85], [64, 68], 0], [[48, 0], 1]), ('low adjust pushes high digit', [[149, 0], [5, 0], 0], [[0, 1], 0]), ('binary carry from high digits', [[153, 153], [153, 5], 0], [[152, 5], 1]), ('carry chains across bytes', [[153, 9, 0], [1, 0, 0], 1], [[1, 16, 0], 0]), ('non-decimal low digit', [[143, 0], [7, 6], 0], [[156, 6], 0]), ('high digit exactly A', [[80, 1], [74, 0], 0], [[0, 2], 0])]]
for label, args, expected in fixtures[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:
Multi-byte BCD sums lose the carry from each lower byte.

Input [xs, ys, c]: little-endian packed-BCD byte lists and a carry-in. For each byte: s = a+b+c; AF = low-nibble sum (with carry) > 0x0F; CF = s > 0xFF; al = s & 0xFF. Decimal adjust: if (al & 0x0F) > 9 or AF then al += 6 (8-bit wrap); then if the pre-adjust al > 0x99 or CF then al += 0x60 (8-bit wrap) and carry-out = 1, else carry-out = 0. The carry-out feeds the next byte. Return [result bytes, final carry].

split: open-access


prompt:
Incrementing 0x0F leaves H clear and incrementing 0x0E sets it.

Input [a, ops]; ops are 'inc', 'dec', ['add', v], ['sub', v] on 8-bit A; carry starts 0. After each op report [A, S, Z, H, PV, N, C]. inc: H = carry out of bit 3, PV = (A was 0x7F), N = 0, C unchanged. dec: H = borrow from bit 4 (low nibble was 0), PV = (A was 0x80), N = 1, C unchanged. add: H = carry out of bit 3, PV = signed overflow, N = 0, C = carry out. sub: H = borrow into bit 4 (low nibble of A < low nibble of v), PV = signed overflow, N = 1, C = borrow.

split: open-access


prompt:
Incrementing 0xFF sets carry, clobbering a carry from an earlier add.

Input [a, ops]; ops are 'inc', 'dec', ['add', v], ['sub', v] on 8-bit A; carry starts 0. After each op report [A, S, Z, H, PV, N, C]. inc: H = carry out of bit 3, PV = (A was 0x7F), N = 0, C unchanged. dec: H = borrow from bit 4 (low nibble was 0), PV = (A was 0x80), N = 1, C unchanged. add: H = carry out of bit 3, PV = signed overflow, N = 0, C = carry out. sub: H = borrow into bit 4 (low nibble of A < low nibble of v), PV = signed overflow, N = 1, C = borrow.

split: open-access


prompt:
Decrementing 0x10 leaves H clear.

Input [a, ops]; ops are 'inc', 'dec', ['add', v], ['sub', v] on 8-bit A; carry starts 0. After each op report [A, S, Z, H, PV, N, C]. inc: H = carry out of bit 3, PV = (A was 0x7F), N = 0, C unchanged. dec: H = borrow from bit 4 (low nibble was 0), PV = (A was 0x80), N = 1, C unchanged. add: H = carry out of bit 3, PV = signed overflow, N = 0, C = carry out. sub: H = borrow into bit 4 (low nibble of A < low nibble of v), PV = signed overflow, N = 1, C = borrow.

split: open-access


prompt:
Subtracting a value with the same low nibble sets H.

Input [a, ops]; ops are 'inc', 'dec', ['add', v], ['sub', v] on 8-bit A; carry starts 0. After each op report [A, S, Z, H, PV, N, C]. inc: H = carry out of bit 3, PV = (A was 0x7F), N = 0, C unchanged. dec: H = borrow from bit 4 (low nibble was 0), PV = (A was 0x80), N = 1, C unchanged. add: H = carry out of bit 3, PV = signed overflow, N = 0, C = carry out. sub: H = borrow into bit 4 (low nibble of A < low nibble of v), PV = signed overflow, N = 1, C = borrow.

split: open-access


prompt:
PV is set when decrementing 0x81 to 0x80 instead of 0x80 to 0x7F.

Input [a, ops]; ops are 'inc', 'dec', ['add', v], ['sub', v] on 8-bit A; carry starts 0. After each op report [A, S, Z, H, PV, N, C]. inc: H = carry out of bit 3, PV = (A was 0x7F), N = 0, C unchanged. dec: H = borrow from bit 4 (low nibble was 0), PV = (A was 0x80), N = 1, C unchanged. add: H = carry out of bit 3, PV = signed overflow, N = 0, C = carry out. sub: H = borrow into bit 4 (low nibble of A < low nibble of v), PV = signed overflow, N = 1, C = borrow.

split: open-access


prompt:
Subtracting a negative from a positive that overflows is not flagged, and harmless subtractions are.

Input [a, ops]; ops are 'inc', 'dec', ['add', v], ['sub', v] on 8-bit A; carry starts 0. After each op report [A, S, Z, H, PV, N, C]. inc: H = carry out of bit 3, PV = (A was 0x7F), N = 0, C unchanged. dec: H = borrow from bit 4 (low nibble was 0), PV = (A was 0x80), N = 1, C unchanged. add: H = carry out of bit 3, PV = signed overflow, N = 0, C = carry out. sub: H = borrow into bit 4 (low nibble of A < low nibble of v), PV = signed overflow, N = 1, C = borrow.

split: open-access


prompt:
Translations use a PTE selected partly by page-offset bits.

Input [va, write, user, root, mem]; mem maps decimal-string physical addresses to 32-bit entries (missing = 0). VA splits 10/10/12 (directory index va>>22, table index (va>>12)&0x3FF, offset). The PDE is at root + 4*dir, the PTE at (PDE frame << 12) + 4*table. Bits: P=1, W=2, U=4, A=32, D=64; frame = entry >> 12. Not present -> ['fault', err]; write without W on both levels or user access without U on both levels -> ['fault', err | 1], where err = 2 if write plus 4 if user. On success set A on both entries and D on the PTE only for writes, returning ['ok', physical address, sorted [address, entry] of memory].

split: open-access


prompt:
A user or write access succeeds through a supervisor-only or read-only directory entry.

Input [va, write, user, root, mem]; mem maps decimal-string physical addresses to 32-bit entries (missing = 0). VA splits 10/10/12 (directory index va>>22, table index (va>>12)&0x3FF, offset). The PDE is at root + 4*dir, the PTE at (PDE frame << 12) + 4*table. Bits: P=1, W=2, U=4, A=32, D=64; frame = entry >> 12. Not present -> ['fault', err]; write without W on both levels or user access without U on both levels -> ['fault', err | 1], where err = 2 if write plus 4 if user. On success set A on both entries and D on the PTE only for writes, returning ['ok', physical address, sorted [address, entry] of memory].

split: open-access


prompt:
A permission violation on a present page has the present bit clear in its error code.

Input [va, write, user, root, mem]; mem maps decimal-string physical addresses to 32-bit entries (missing = 0). VA splits 10/10/12 (directory index va>>22, table index (va>>12)&0x3FF, offset). The PDE is at root + 4*dir, the PTE at (PDE frame << 12) + 4*table. Bits: P=1, W=2, U=4, A=32, D=64; frame = entry >> 12. Not present -> ['fault', err]; write without W on both levels or user access without U on both levels -> ['fault', err | 1], where err = 2 if write plus 4 if user. On success set A on both entries and D on the PTE only for writes, returning ['ok', physical address, sorted [address, entry] of memory].

split: open-access


prompt:
Reading a page marks it dirty.

Input [va, write, user, root, mem]; mem maps decimal-string physical addresses to 32-bit entries (missing = 0). VA splits 10/10/12 (directory index va>>22, table index (va>>12)&0x3FF, offset). The PDE is at root + 4*dir, the PTE at (PDE frame << 12) + 4*table. Bits: P=1, W=2, U=4, A=32, D=64; frame = entry >> 12. Not present -> ['fault', err]; write without W on both levels or user access without U on both levels -> ['fault', err | 1], where err = 2 if write plus 4 if user. On success set A on both entries and D on the PTE only for writes, returning ['ok', physical address, sorted [address, entry] of memory].

split: open-access


prompt:
After a walk the directory entry still reads as unaccessed.

Input [va, write, user, root, mem]; mem maps decimal-string physical addresses to 32-bit entries (missing = 0). VA splits 10/10/12 (directory index va>>22, table index (va>>12)&0x3FF, offset). The PDE is at root + 4*dir, the PTE at (PDE frame << 12) + 4*table. Bits: P=1, W=2, U=4, A=32, D=64; frame = entry >> 12. Not present -> ['fault', err]; write without W on both levels or user access without U on both levels -> ['fault', err | 1], where err = 2 if write plus 4 if user. On success set A on both entries and D on the PTE only for writes, returning ['ok', physical address, sorted [address, entry] of memory].

split: open-access


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

N = 1
observations = []
def solve(*args):
    prog, limit = args
    r = [0] * 8
    pc = 0
    trace = []
    pending = None
    steps = 0
    while steps < limit:
        steps += 1
        ins = prog[pc // 4] if 0 <= pc // 4 < len(prog) else ['halt']
        trace.append(pc)
        op = ins[0]
        nxt = pc + 4
        if op == 'halt':
            break
        if op == 'addi':
            if ins[1]:
                r[ins[1]] = r[ins[2]] + ins[3]
        elif op in ('beq', 'bne', 'beql'):
            taken = (r[ins[1]] == r[ins[2]]) == (op != 'bne')
            off = ins[3] - 0x10000 if ins[3] & 0x8000 else ins[3]
            tgt = pc + (off << 2)
            if op == 'beql' and not taken:
                nxt = pc + 8
            else:
                pending = tgt if taken else pc + 8
        elif op == 'j':
            pending = ((pc + 4) & 0xF0000000) | (ins[1] << 2)
        if pending is not None and op not in ('beq', 'bne', 'beql', 'j'):
            nxt = pending
            pending = None
        pc = nxt
    return [trace, r]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('forward taken beq', [[['addi', 1, 0, 3], ['beq', 0, 0, 2], ['addi', 2, 2, 1], ['addi', 3, 0, 9], ['halt']], 40], [[0, 4, 8, 16], [0, 3, 1, 0, 0, 0, 0, 0]]), ('backward counted loop', [[['addi', 1, 0, 2], ['addi', 2, 2, 2], ['addi', 1, 1, -1], ['bne', 1, 0, 65533], ['addi', 3, 3, 1], ['halt']], 60], [[0, 4, 8, 12, 16, 4, 8, 12, 16, 20], [0, 0, 4, 2, 0, 0, 0, 0]]), ('branch likely not taken annuls slot', [[['addi', 1, 0, 1], ['beql', 1, 0, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['halt']], 40], [[0, 4, 12, 16], [0, 1, 0, 4, 0, 0, 0, 0]]), ('branch likely taken runs slot', [[['addi', 1, 0, 1], ['beql', 1, 1, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['addi', 4, 0, 5], ['halt']], 40], [[0, 4, 8, 16, 20], [0, 1, 7, 0, 5, 0, 0, 0]]), ('zero register and jump', [[['addi', 1, 0, 3], ['addi', 0, 1, 5], ['addi', 4, 0, 1], ['j', 5], ['addi', 5, 4, 1], ['addi', 6, 0, 3], ['halt']], 40], [[0, 4, 8, 12, 16, 20, 24], [0, 3, 0, 0, 1, 2, 3, 0]]), ('bne with nop slot', [[['addi', 1, 0, 1], ['bne', 1, 0, 3], ['nop'], ['addi', 7, 0, 1], ['halt'], ['addi', 6, 1, 1], ['halt']], 40], [[0, 4, 8, 20, 24], [0, 1, 0, 0, 0, 0, 2, 0]])], [('forward taken beq', [[['addi', 1, 0, 3], ['beq', 0, 0, 2], ['addi', 2, 2, 1], ['addi', 3, 0, 9], ['halt']], 40], [[0, 4, 8, 16], [0, 3, 1, 0, 0, 0, 0, 0]]), ('backward counted loop', [[['addi', 1, 0, 3], ['addi', 2, 2, 2], ['addi', 1, 1, -1], ['bne', 1, 0, 65533], ['addi', 3, 3, 1], ['halt']], 60], [[0, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 20], [0, 0, 6, 3, 0, 0, 0, 0]]), ('branch likely not taken annuls slot', [[['addi', 1, 0, 1], ['beql', 1, 0, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['halt']], 40], [[0, 4, 12, 16], [0, 1, 0, 4, 0, 0, 0, 0]]), ('branch likely taken runs slot', [[['addi', 1, 0, 1], ['beql', 1, 1, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['addi', 4, 0, 5], ['halt']], 40], [[0, 4, 8, 16, 20], [0, 1, 7, 0, 5, 0, 0, 0]]), ('zero register and jump', [[['addi', 1, 0, 4], ['addi', 0, 1, 5], ['addi', 4, 0, 1], ['j', 5], ['addi', 5, 4, 1], ['addi', 6, 0, 3], ['halt']], 40], [[0, 4, 8, 12, 16, 20, 24], [0, 4, 0, 0, 1, 2, 3, 0]]), ('bne with nop slot', [[['addi', 1, 0, 1], ['bne', 1, 0, 3], ['nop'], ['addi', 7, 0, 1], ['halt'], ['addi', 6, 1, 2], ['halt']], 40], [[0, 4, 8, 20, 24], [0, 1, 0, 0, 0, 0, 3, 0]])], [('forward taken beq', [[['addi', 1, 0, 3], ['beq', 0, 0, 2], ['addi', 2, 2, 1], ['addi', 3, 0, 9], ['halt']], 40], [[0, 4, 8, 16], [0, 3, 1, 0, 0, 0, 0, 0]]), ('backward counted loop', [[['addi', 1, 0, 4], ['addi', 2, 2, 2], ['addi', 1, 1, -1], ['bne', 1, 0, 65533], ['addi', 3, 3, 1], ['halt']], 60], [[0, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 20], [0, 0, 8, 4, 0, 0, 0, 0]]), ('branch likely not taken annuls slot', [[['addi', 1, 0, 1], ['beql', 1, 0, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['halt']], 40], [[0, 4, 12, 16], [0, 1, 0, 4, 0, 0, 0, 0]]), ('branch likely taken runs slot', [[['addi', 1, 0, 1], ['beql', 1, 1, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['addi', 4, 0, 5], ['halt']], 40], [[0, 4, 8, 16, 20], [0, 1, 7, 0, 5, 0, 0, 0]]), ('zero register and jump', [[['addi', 1, 0, 5], ['addi', 0, 1, 5], ['addi', 4, 0, 1], ['j', 5], ['addi', 5, 4, 1], ['addi', 6, 0, 3], ['halt']], 40], [[0, 4, 8, 12, 16, 20, 24], [0, 5, 0, 0, 1, 2, 3, 0]]), ('bne with nop slot', [[['addi', 1, 0, 1], ['bne', 1, 0, 3], ['nop'], ['addi', 7, 0, 1], ['halt'], ['addi', 6, 1, 3], ['halt']], 40], [[0, 4, 8, 20, 24], [0, 1, 0, 0, 0, 0, 4, 0]])], [('forward taken beq', [[['addi', 1, 0, 3], ['beq', 0, 0, 2], ['addi', 2, 2, 1], ['addi', 3, 0, 9], ['halt']], 40], [[0, 4, 8, 16], [0, 3, 1, 0, 0, 0, 0, 0]]), ('backward counted loop', [[['addi', 1, 0, 5], ['addi', 2, 2, 2], ['addi', 1, 1, -1], ['bne', 1, 0, 65533], ['addi', 3, 3, 1], ['halt']], 60], [[0, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 20], [0, 0, 10, 5, 0, 0, 0, 0]]), ('branch likely not taken annuls slot', [[['addi', 1, 0, 1], ['beql', 1, 0, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['halt']], 40], [[0, 4, 12, 16], [0, 1, 0, 4, 0, 0, 0, 0]]), ('branch likely taken runs slot', [[['addi', 1, 0, 1], ['beql', 1, 1, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['addi', 4, 0, 5], ['halt']], 40], [[0, 4, 8, 16, 20], [0, 1, 7, 0, 5, 0, 0, 0]]), ('zero register and jump', [[['addi', 1, 0, 6], ['addi', 0, 1, 5], ['addi', 4, 0, 1], ['j', 5], ['addi', 5, 4, 1], ['addi', 6, 0, 3], ['halt']], 40], [[0, 4, 8, 12, 16, 20, 24], [0, 6, 0, 0, 1, 2, 3, 0]]), ('bne with nop slot', [[['addi', 1, 0, 1], ['bne', 1, 0, 3], ['nop'], ['addi', 7, 0, 1], ['halt'], ['addi', 6, 1, 4], ['halt']], 40], [[0, 4, 8, 20, 24], [0, 1, 0, 0, 0, 0, 5, 0]])], [('forward taken beq', [[['addi', 1, 0, 3], ['beq', 0, 0, 2], ['addi', 2, 2, 1], ['addi', 3, 0, 9], ['halt']], 40], [[0, 4, 8, 16], [0, 3, 1, 0, 0, 0, 0, 0]]), ('backward counted loop', [[['addi', 1, 0, 6], ['addi', 2, 2, 2], ['addi', 1, 1, -1], ['bne', 1, 0, 65533], ['addi', 3, 3, 1], ['halt']], 60], [[0, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 20], [0, 0, 12, 6, 0, 0, 0, 0]]), ('branch likely not taken annuls slot', [[['addi', 1, 0, 1], ['beql', 1, 0, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['halt']], 40], [[0, 4, 12, 16], [0, 1, 0, 4, 0, 0, 0, 0]]), ('branch likely taken runs slot', [[['addi', 1, 0, 1], ['beql', 1, 1, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['addi', 4, 0, 5], ['halt']], 40], [[0, 4, 8, 16, 20], [0, 1, 7, 0, 5, 0, 0, 0]]), ('zero register and jump', [[['addi', 1, 0, 7], ['addi', 0, 1, 5], ['addi', 4, 0, 1], ['j', 5], ['addi', 5, 4, 1], ['addi', 6, 0, 3], ['halt']], 40], [[0, 4, 8, 12, 16, 20, 24], [0, 7, 0, 0, 1, 2, 3, 0]]), ('bne with nop slot', [[['addi', 1, 0, 1], ['bne', 1, 0, 3], ['nop'], ['addi', 7, 0, 1], ['halt'], ['addi', 6, 1, 5], ['halt']], 40], [[0, 4, 8, 20, 24], [0, 1, 0, 0, 0, 0, 6, 0]])]]
for label, args, expected in fixtures[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(*args):
    prog, limit = args
    r = [0] * 8
    pc = 0
    trace = []
    pending = None
    steps = 0
    while steps < limit:
        steps += 1
        ins = prog[pc // 4] if 0 <= pc // 4 < len(prog) else ['halt']
        trace.append(pc)
        op = ins[0]
        nxt = pc + 4
        if op == 'halt':
            break
        if op == 'addi':
            if ins[1]:
                r[ins[1]] = r[ins[2]] + ins[3]
        elif op in ('beq', 'bne', 'beql'):
            taken = (r[ins[1]] == r[ins[2]]) == (op != 'bne')
            off = ins[3] - 0x10000 if ins[3] & 0x8000 else ins[3]
            tgt = pc + 8 + (off << 2)
            if op == 'beql' and not taken:
                nxt = pc + 8
            else:
                pending = tgt if taken else pc + 8
        elif op == 'j':
            pending = ((pc + 4) & 0xF0000000) | (ins[1] << 2)
        if pending is not None and op not in ('beq', 'bne', 'beql', 'j'):
            nxt = pending
            pending = None
        pc = nxt
    return [trace, r]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('forward taken beq', [[['addi', 1, 0, 3], ['beq', 0, 0, 2], ['addi', 2, 2, 1], ['addi', 3, 0, 9], ['halt']], 40], [[0, 4, 8, 16], [0, 3, 1, 0, 0, 0, 0, 0]]), ('backward counted loop', [[['addi', 1, 0, 2], ['addi', 2, 2, 2], ['addi', 1, 1, -1], ['bne', 1, 0, 65533], ['addi', 3, 3, 1], ['halt']], 60], [[0, 4, 8, 12, 16, 4, 8, 12, 16, 20], [0, 0, 4, 2, 0, 0, 0, 0]]), ('branch likely not taken annuls slot', [[['addi', 1, 0, 1], ['beql', 1, 0, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['halt']], 40], [[0, 4, 12, 16], [0, 1, 0, 4, 0, 0, 0, 0]]), ('branch likely taken runs slot', [[['addi', 1, 0, 1], ['beql', 1, 1, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['addi', 4, 0, 5], ['halt']], 40], [[0, 4, 8, 16, 20], [0, 1, 7, 0, 5, 0, 0, 0]]), ('zero register and jump', [[['addi', 1, 0, 3], ['addi', 0, 1, 5], ['addi', 4, 0, 1], ['j', 5], ['addi', 5, 4, 1], ['addi', 6, 0, 3], ['halt']], 40], [[0, 4, 8, 12, 16, 20, 24], [0, 3, 0, 0, 1, 2, 3, 0]]), ('bne with nop slot', [[['addi', 1, 0, 1], ['bne', 1, 0, 3], ['nop'], ['addi', 7, 0, 1], ['halt'], ['addi', 6, 1, 1], ['halt']], 40], [[0, 4, 8, 20, 24], [0, 1, 0, 0, 0, 0, 2, 0]])], [('forward taken beq', [[['addi', 1, 0, 3], ['beq', 0, 0, 2], ['addi', 2, 2, 1], ['addi', 3, 0, 9], ['halt']], 40], [[0, 4, 8, 16], [0, 3, 1, 0, 0, 0, 0, 0]]), ('backward counted loop', [[['addi', 1, 0, 3], ['addi', 2, 2, 2], ['addi', 1, 1, -1], ['bne', 1, 0, 65533], ['addi', 3, 3, 1], ['halt']], 60], [[0, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 20], [0, 0, 6, 3, 0, 0, 0, 0]]), ('branch likely not taken annuls slot', [[['addi', 1, 0, 1], ['beql', 1, 0, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['halt']], 40], [[0, 4, 12, 16], [0, 1, 0, 4, 0, 0, 0, 0]]), ('branch likely taken runs slot', [[['addi', 1, 0, 1], ['beql', 1, 1, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['addi', 4, 0, 5], ['halt']], 40], [[0, 4, 8, 16, 20], [0, 1, 7, 0, 5, 0, 0, 0]]), ('zero register and jump', [[['addi', 1, 0, 4], ['addi', 0, 1, 5], ['addi', 4, 0, 1], ['j', 5], ['addi', 5, 4, 1], ['addi', 6, 0, 3], ['halt']], 40], [[0, 4, 8, 12, 16, 20, 24], [0, 4, 0, 0, 1, 2, 3, 0]]), ('bne with nop slot', [[['addi', 1, 0, 1], ['bne', 1, 0, 3], ['nop'], ['addi', 7, 0, 1], ['halt'], ['addi', 6, 1, 2], ['halt']], 40], [[0, 4, 8, 20, 24], [0, 1, 0, 0, 0, 0, 3, 0]])], [('forward taken beq', [[['addi', 1, 0, 3], ['beq', 0, 0, 2], ['addi', 2, 2, 1], ['addi', 3, 0, 9], ['halt']], 40], [[0, 4, 8, 16], [0, 3, 1, 0, 0, 0, 0, 0]]), ('backward counted loop', [[['addi', 1, 0, 4], ['addi', 2, 2, 2], ['addi', 1, 1, -1], ['bne', 1, 0, 65533], ['addi', 3, 3, 1], ['halt']], 60], [[0, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 20], [0, 0, 8, 4, 0, 0, 0, 0]]), ('branch likely not taken annuls slot', [[['addi', 1, 0, 1], ['beql', 1, 0, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['halt']], 40], [[0, 4, 12, 16], [0, 1, 0, 4, 0, 0, 0, 0]]), ('branch likely taken runs slot', [[['addi', 1, 0, 1], ['beql', 1, 1, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['addi', 4, 0, 5], ['halt']], 40], [[0, 4, 8, 16, 20], [0, 1, 7, 0, 5, 0, 0, 0]]), ('zero register and jump', [[['addi', 1, 0, 5], ['addi', 0, 1, 5], ['addi', 4, 0, 1], ['j', 5], ['addi', 5, 4, 1], ['addi', 6, 0, 3], ['halt']], 40], [[0, 4, 8, 12, 16, 20, 24], [0, 5, 0, 0, 1, 2, 3, 0]]), ('bne with nop slot', [[['addi', 1, 0, 1], ['bne', 1, 0, 3], ['nop'], ['addi', 7, 0, 1], ['halt'], ['addi', 6, 1, 3], ['halt']], 40], [[0, 4, 8, 20, 24], [0, 1, 0, 0, 0, 0, 4, 0]])], [('forward taken beq', [[['addi', 1, 0, 3], ['beq', 0, 0, 2], ['addi', 2, 2, 1], ['addi', 3, 0, 9], ['halt']], 40], [[0, 4, 8, 16], [0, 3, 1, 0, 0, 0, 0, 0]]), ('backward counted loop', [[['addi', 1, 0, 5], ['addi', 2, 2, 2], ['addi', 1, 1, -1], ['bne', 1, 0, 65533], ['addi', 3, 3, 1], ['halt']], 60], [[0, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 20], [0, 0, 10, 5, 0, 0, 0, 0]]), ('branch likely not taken annuls slot', [[['addi', 1, 0, 1], ['beql', 1, 0, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['halt']], 40], [[0, 4, 12, 16], [0, 1, 0, 4, 0, 0, 0, 0]]), ('branch likely taken runs slot', [[['addi', 1, 0, 1], ['beql', 1, 1, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['addi', 4, 0, 5], ['halt']], 40], [[0, 4, 8, 16, 20], [0, 1, 7, 0, 5, 0, 0, 0]]), ('zero register and jump', [[['addi', 1, 0, 6], ['addi', 0, 1, 5], ['addi', 4, 0, 1], ['j', 5], ['addi', 5, 4, 1], ['addi', 6, 0, 3], ['halt']], 40], [[0, 4, 8, 12, 16, 20, 24], [0, 6, 0, 0, 1, 2, 3, 0]]), ('bne with nop slot', [[['addi', 1, 0, 1], ['bne', 1, 0, 3], ['nop'], ['addi', 7, 0, 1], ['halt'], ['addi', 6, 1, 4], ['halt']], 40], [[0, 4, 8, 20, 24], [0, 1, 0, 0, 0, 0, 5, 0]])], [('forward taken beq', [[['addi', 1, 0, 3], ['beq', 0, 0, 2], ['addi', 2, 2, 1], ['addi', 3, 0, 9], ['halt']], 40], [[0, 4, 8, 16], [0, 3, 1, 0, 0, 0, 0, 0]]), ('backward counted loop', [[['addi', 1, 0, 6], ['addi', 2, 2, 2], ['addi', 1, 1, -1], ['bne', 1, 0, 65533], ['addi', 3, 3, 1], ['halt']], 60], [[0, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 4, 8, 12, 16, 20], [0, 0, 12, 6, 0, 0, 0, 0]]), ('branch likely not taken annuls slot', [[['addi', 1, 0, 1], ['beql', 1, 0, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['halt']], 40], [[0, 4, 12, 16], [0, 1, 0, 4, 0, 0, 0, 0]]), ('branch likely taken runs slot', [[['addi', 1, 0, 1], ['beql', 1, 1, 2], ['addi', 2, 0, 7], ['addi', 3, 0, 4], ['addi', 4, 0, 5], ['halt']], 40], [[0, 4, 8, 16, 20], [0, 1, 7, 0, 5, 0, 0, 0]]), ('zero register and jump', [[['addi', 1, 0, 7], ['addi', 0, 1, 5], ['addi', 4, 0, 1], ['j', 5], ['addi', 5, 4, 1], ['addi', 6, 0, 3], ['halt']], 40], [[0, 4, 8, 12, 16, 20, 24], [0, 7, 0, 0, 1, 2, 3, 0]]), ('bne with nop slot', [[['addi', 1, 0, 1], ['bne', 1, 0, 3], ['nop'], ['addi', 7, 0, 1], ['halt'], ['addi', 6, 1, 5], ['halt']], 40], [[0, 4, 8, 20, 24], [0, 1, 0, 0, 0, 0, 6, 0]])]]
for label, args, expected in fixtures[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:
Taken branches land one instruction early.

Input [prog, limit]: word-indexed instructions at byte addresses 4*i: addi rt rs imm, beq/bne/beql rs rt off16, j index, nop, halt; 8 registers with r0 hardwired to 0. Branch target = branch address + 4 + (sign-extended off16 << 2). The instruction after a branch or jump (its delay slot) always executes before control transfers, except that a not-taken beql skips (annuls) its slot. j target = ((pc+4) & 0xF0000000) | (index << 2). Addresses outside the program behave as halt. Return [executed pcs, registers].

split: open-access