Reading Compiler Output

What clang -O2 makes of everyday C: branchless selects, loops, and division by multiplication.

The most common reason engineers read assembly is to see what the compiler produced: to check a hot loop, understand a crash address, or verify that a volatile access really happens. Here is real compiler output for four small C functions.

What to notice

Judging performance from -O0 output Read the optimized build (-O2/-Os) that you actually ship

Unoptimized code stores every variable on the stack and looks nothing like the release build.

Why does the compiler replace x / 10 with a multiplication?

Division instructions take many cycles (or do not exist on small cores); multiplying by a precomputed reciprocal and shifting gives the same result for all inputs much faster.