title: Force GCC not to rearrange some part of the code
body: <p>I have a program that is very time critical and I want to measure the time it takes to execute the program. Here is a simple schematic of the code.</p>
  
  <pre><code>clock1=current_time();
  instruction 1;
  instruction 2;
  .
  .
  .
  .
  instruction n;
  clock2=current_time();
  total time = clock2-clock1;
  </code></pre>
  
  <p>When I am using GCC to compile the above code with -O2 or -O3 option it always moves clock2=current_time() in the middle of the instructions. Hence giving wrong results.
  Is there any way to restrict gcc not to rearrange this part of the code while optimizing all other parts of the code?
  Some requirements,The routine to measure time is unchangeable. I have to use the routine provided.
  Thank you for your help.
  Regards.</p>
  
  <p>Update : with breakpoints</p>
  
  <pre><code>clock1=0;clock2=0;
  clock1=current_time();
  breakpoint 1 : instruction 1; // clock1=&lt;value&gt; clock2=0
  instruction 2;
  .
  .
  .
  .
  breakpoint 2 : instruction n;// clock1=&lt;value&gt; clock2=&lt;value&gt;
  clock2=current_time();
  total time = clock2-clock1;
  breakpoint 3:// clock1=&lt;value&gt; clock2=&lt;value&gt; total time=clock2-clock1;
  </code></pre>