Busy-Wait Delay Loop

Easy C Timing Asked at STMicroelectronics
Solve this problem

Implement a blocking delay loop that counts down from an integer n to 0. The loop must not be optimized away by the compiler.

Return the final value of the counter.

This mimics bare-metal delay routines used when hardware timers are unavailable.

Input: An integer n. Output: 0 after the delay completes.

Constraints

  • Use a busy-wait loop.
  • Ensure the loop variable is not optimized away.
  • No library delay functions.
Starter codeC
1int delay_loop(int n) {2    // Implement a delay loop3    return n;4}