title: Optimize a function in a search biggest square algorithm
body: <p>I'm kind of new to optimization and I'm in a friendly contest to code the fastest algorithm to find a square in a field with obstacles. I think my algorithm is pretty fast (2.07s in a 10k * 10k grid with 70% density) but I'd like to make it faster. My most used function is the one finding the max size for given coordinates in the square. Here it is :</p>
  
  <pre><code>int     max_size(int i, int j, int **tab, int offset)
  {
  int a;
  
  a = offset;
  if (i &gt; 0 &amp;&amp; j &gt; 0)
  {
      while (i + a &lt; g_ymax &amp;&amp; j + a &lt; g_xmax &amp;&amp; tab[i + a][j + a] - tab[i + a][j - 1] - tab[i - 1][j + a] + tab[i - 1][j - 1] == 0)
          a++;
      return (a);
  }
  else if (i &gt; 0 &amp;&amp; j == 0)
  {
      while (i + a &lt; g_ymax &amp;&amp; j + a &lt; g_xmax &amp;&amp; tab[i + a][j + a] - tab[i - 1][j + a] == 0)
          a++;
      return (a);
  }
  else if (i == 0 &amp;&amp; j &gt; 0)
  {
      while (i + a &lt; g_ymax &amp;&amp; j + a &lt; g_xmax &amp;&amp; tab[i + a][j + a] - tab[i + a][j - 1] == 0)
          a++;
      return (a);
  }
  else
  {
      while (i + a &lt; g_ymax &amp;&amp; j + a &lt; g_xmax &amp;&amp; tab[i + a][j + a] == 0)
          a++;
      return (a);
  }
  }
  </code></pre>
  
  <p>So this is very ugly and I'd like to optimize it. Would make it an inline function help or not at all ? I tried to run some tests but I didn't see much differences. </p>