"""Offline memory-role/arithmetic model; no hardware or physical-memory writes.
Not an implementation of a power-fail-safe storage driver.
SPDX-License-Identifier: MIT
Copyright (c) 2026 LCENJ
"""
import json

def boot(nonvolatile):
    # Hypothetical application range; not a component specification.
    saved = nonvolatile.get("interval_ms")
    interval = saved if isinstance(saved, int) and 100 <= saved <= 5000 else 1000
    return {"program": nonvolatile["program"], "interval_ms": interval,
            "counter": 0}  # Software initialization, not physical SRAM zeroing.

def check():
    original = {"program": "toggle-v1", "interval_ms": 1000}
    working = boot(original)
    working.update(interval_ms=500, counter=7)  # Not saved.
    after_unsaved = boot(original)
    saved = {**original, "interval_ms": 500}  # Assume complete valid save.
    after_saved = boot(saved)
    checks = [
        working["interval_ms"] == 500,
        after_unsaved["interval_ms"] == 1000,
        after_saved["interval_ms"] == 500,
        after_saved["counter"] == 0,
        after_saved["program"] == original["program"],
        boot({"program": "toggle-v1", "interval_ms": 50000})["interval_ms"] == 1000,
        (32 - 24 - 4) * 1024 == 4096,
        100 * 2 * 2 == 400,
        500 / 1000 == 0.5,
        (500 + 500) / 1000 == 1.0,
        24 * 60 * 60 == 86400,
        24 * 60 == 1440,
        86400 / 1440 == 60,
    ]
    assert all(checks)
    return {"passed_checks": len(checks), "unsaved_restart": after_unsaved,
            "saved_restart": after_saved, "storage_spare_bytes": 4096,
            "sample_array_bytes": 400,
            "scope": "Behavior and arithmetic only; no Flash/MRAM operation, atomic-write algorithm or hardware test"}

if __name__ == "__main__":
    print(json.dumps(check(), indent=2))
