\begin{tikzpicture}[ node distance=0.8cm and 1.1cm, box/.style={draw, rounded corners, minimum width=3cm, minimum height=1cm, align=center}, arrow/.style={-{Stealth}, thick}, decision/.style={diamond, draw, aspect=2, align=center}, io/.style={trapezium, trapezium left angle=70, trapezium right angle=110, draw, minimum width=2.5cm, align=center} ] % Nodes \node[box] (start) {record\_card():\\ Init PcscLink, Card, Recorder}; \node[box, below=of start] (scenarioLoop) {For each Scenario\\ Instantiate and Run Scenario.run(card)}; \node[box, below=of scenarioLoop] (isdrcall) {Card ISD-R command}; % Mutation engine path \node[decision, below=of isdrcall] (mutateQ) {Mutation\\ Engine?}; \node[box, right=1.2cm of mutateQ] (originalAPDU) {Send original APDU}; \node[box, left=1.2cm of mutateQ] (mutateAPDU) {Get next mutation\\ and Mutate APDU}; \node[box, below=of mutateQ] (sendAPDU) {Transmit APDU to card}; \node[box, below=of sendAPDU] (record) {Record mutation result\\ in OperationRecorder}; % Error / reset path \node[decision, below=of record] (errorQ) {Exception\\ during scenario?}; \node[box, left=of errorQ] (logFail) {Log failure\\ in current\\ mutation node}; \node[box, below=of errorQ] (checkTree) {All mutations tried?}; \node[box, right=of checkTree] (repeatScenario) {Repeat Scenario}; \node[box, below=of checkTree] (saveFile) {Save .resim file}; \node[box, below=of saveFile] (clearReset) {Clear recorder,\\ Reset card}; % Arrows \draw[arrow] (start) -- (scenarioLoop); \draw[arrow] (scenarioLoop) -- (isdrcall); \draw[arrow] (isdrcall) -- (mutateQ); \draw[arrow] (mutateQ) -- node[above] {No} (originalAPDU); \draw[arrow] (mutateQ) -- node[above] {Yes} (mutateAPDU); \draw[arrow] (mutateAPDU) |- (sendAPDU); \draw[arrow] (originalAPDU) |- (sendAPDU); \draw[arrow] (sendAPDU) -- (record); \draw[arrow] (record) -- (errorQ); \draw[arrow] (errorQ) -- node[above] {Yes} (logFail); \draw[arrow] (logFail) |- (checkTree); \draw[arrow] (errorQ) -- node[right] {No} (checkTree); \draw[arrow] (checkTree) -- node[above] {No} (repeatScenario); \draw[arrow] (checkTree) -- node[right] {Yes} (saveFile); \draw[arrow] (saveFile) -- (clearReset); \end{tikzpicture}