\newpage
\subsection{Control Flow}

Control flow structures from \verb|C| like \verb|if/else| or \verb|for| are compiled into assembly mainly using jumps and conditional \verb|move|.

By the nature of Assembly and thanks to compilers optimizing aggressively, there is no \textit{single} definitive translation of the \verb|C| control structures:
The compiler may translate it very differently depending on the context of the program.

\subsubsection{Conditional statements}
A function using an \verb|if/else| construct to choose the maximum of $2$ numbers might compile like this:

\inputcodewithfilename{gas}{}{code-examples/01_asm/02_max.s}

A function computing the absolute difference $|x-y|$ using an \verb|if/else| construct, might use a conditional \verb|move| instead:

\inputcodewithfilename{gas}{}{code-examples/01_asm/03_absdiff.s}

\subsubsection{While Loops}

A recursive factorial function using a \verb|do while| loop may be compiled like this:

\inputcodewithfilename{gas}{}{code-examples/01_asm/04_factorial.s}

\newpage

The same function, using a \verb|while| loop instead may lead to this:

\inputcodewithfilename{gas}{}{code-examples/01_asm/05_factorial.s}

\subsubsection{For Loops \& Switch}

\verb|for| loops follow the same idea as \verb|while| loops, albeit with a few more jumps.

\verb|switch| statements are implemented differently depending on size and case values: 
Sparse switch statements are compiled as decision trees, whereas compact switch statements may become \textit{jump tables}.

These jump tables are usually stored in the \texttt{.rodata} section with 8-byte alignment. The jump uses offsets:
\mint{gas}|jmp *.LABEL(, %rsi, 8)|
and we jump to the effective address of \texttt{.LABEL + rsi * 8}
