@startuml
scale 820 width
top to bottom direction
skinparam backgroundColor transparent
skinparam shadowing false
skinparam defaultFontName Monospace
skinparam defaultFontSize 9
skinparam rectangleBorderColor #2c7794
skinparam rectangleBackgroundColor #edf6fa
skinparam ArrowColor #8095a1
title A5 FLOW — allocate, fragment, coalesce, verify

rectangle "01 RESET\ninitial free = 4080" as S1
rectangle "02 ALLOC A\n24 byte payload\nfirst-fit + split" as S2
rectangle "03 ALLOC B / C\n40 + 16 byte payload\nafter = 3952" as S3
rectangle "04 FREE A / C\nB remains allocated" as S4
rectangle "05 E01 FRAGMENTED\n2 free blocks\ncurrent > largest" as S5
rectangle "06 FREE B\ninsert by address\njoin right + left" as S6
rectangle "07 E02 COALESCED\n1 free block\nfinal = initial" as S7
rectangle "08 OOM CHECK\nNULL · hook=1\nasserts=0 · PASS=1" as S8

S1 -right-> S2 : pvPortMalloc
S2 -right-> S3 : split remainder
S3 -right-> S4 : vPortFree
S4 -down-> S5 : heap stats
S5 -left-> S6 : continue
S6 -left-> S7 : coalesce
S7 -left-> S8 : oversized request
@enduml
