```bash
#!/usr/bin/env bash
# Purpose: Lint dispatch report footer.
# Usage:   bash tools/check-footer.sh <REPORT_PATH>
# Behavior: Verifies USAGE line and NATIVE FOOTPRINT block in a single fenced code block at the end of the report.
# Output:  PASS
#          FAIL: <n> <reason>
# Exit:    0 on PASS
#          1 on any FAIL
#          2 if report not readable
# Author:  FVC 36 (id 44, 2026-09-22)

set -u
set -o pipefail

REPORT="$1"

# Check readability
if ! [ -r "$REPORT" ]; then
  echo "FAIL: 2 report not readable: $REPORT"
  exit 2
fi

# [1] USAGE line must exist
if ! grep -q '^USAGE:' "$REPORT"; then
  echo "FAIL: 1 USAGE line missing"
  exit 1
fi

# [2] Find fenced code blocks
fence_lines=$(grep -n '^```' "$REPORT" | cut -d: -f1)
fence_count=$(echo "$fence_lines" | wc -l)
if [ "$fence_count" -eq 0 ] || [ $((fence_count % 2)) -ne 0 ]; then
  echo "FAIL: 2 footer block missing or invalid"
  exit 1
fi

# Determine last matching block
last_start=0
last_end=0
while read -r start; do
  read -r end
  block=$(sed -n "${start},${end}p" "$REPORT")
  if echo "$block" | grep -q '^USAGE:' && echo "$block" | grep -q -E 'NATIVE FOOTPRINT|\[1\]'; then
    last_start=$start
    last_end=$end
  fi
done < <(echo "$fence_lines" | awk 'NR%2==1{start=$0} NR%2==0{end=$0; print start, end}')

if [ "$last_start" -eq 0 ]; then
  echo "FAIL: 2 footer block missing or invalid"
  exit 1
fi

# [3] Footer block must be last non‑empty content
last_nonempty=$(awk 'NF{n=NR} END{print n+0}' "$REPORT")
if [ "$last_end" -lt "$last_nonempty" ]; then
  echo "FAIL: 3 footer block not last content"
  exit 1
fi

echo "PASS"
exit 0
```