user61410: When I write code like this:
int a = 7
int b = 2
int c = a/b
int r = a%b

Does the chip use the remainder while calculating c or does it redo the entire calculation?

user23644: The compiler is only as smart as you provide it the necessary information.

It is good to examine code on godbolt.com. But use it wisely.
Noone should ever compile without optimizations. In the example above the code is not optimized and thus would never been used as such on a board.
The example is so artificial that the compiler optimizes it away into just 2 instructions. So the code should be representative for the intended usage.
A better godbolt would be:

#include<stdint.h>
#include<stdlib.h>

void myDiv(uint8_t * c, uint8_t * r, const uint8_t a, const uint8_t b) {
    *c = a/b;
    *r = a%b;
}

So the input is not predetermined and also the resulting numbers are returned and not thrown away. Which translates with -Os to:
myDiv(unsigned char*, unsigned char*, unsigned char, unsigned char):
        mov r27,r25
        mov r26,r24
        mov r31,r23
        mov r30,r22
        mov r24,r20
        mov r22,r18
        rcall __udivmodqi4
        st X,r24
        st Z,r25
        ret


There is the div(numerator, denominator) function in stdlib.h. This function performs a division and returns both the dividend and the remainder. It is optimized for each platform and uses the best available method to get both. In Godbolt it would look like this:

#include<stdint.h>
#include<stdlib.h>

void myDiv2(uint8_t * c, uint8_t * r, const uint8_t a, const uint8_t b) {
    div_t d = div(a, b);
    *c = d.quot;
    *r = d.rem;
}


But what surprise, with -Os the resulting assembly looks exactly the same! (I leave it to the reader to try it on godbolt).
That means, the compiler is smart enough to:
a. recognise the intention when calling division and modulo an the same operands successively.
b. will use the best available method to achieve the intended calculation for you.

EDIT after Edgar Bonet's comment:
While playing around in godbolt I made a copy-paste mistake. div only applies to int values. That makes the resulting assembly code larger as there has twice the data to be shoveld around. After changing both examples to int they look almost similar. The only difference is:
The result is stored in d first and then copied to c and r.
So the division/modulo code is more efficient in that regard as the resulting values are copied directly from the registers used in the calling convention.
https://godbolt.org/z/61exz7

user50183: If using optimization, the compiler is smart enough to recognize this.
Since your example is so short, it could be optimized away entirely.
To ensure that doesn't happen, the results in c and r have to be used in some way.
Also, if a and b could never change, the values of c and r would be calculated during compilation.
Therefore, I put the calculation in its own function.
From godbolt.com, using AVR-GCC 9.2.0:
#include<stdint.h>
#include<stdio.h>

uint8_t a = 0;
uint8_t b = 2;
uint8_t c = 0;
uint8_t r = 0;

void calculate() {
    c = a / b;
    r = a % b;
}

int main() {
    a = 7;
    b = 2;

    calculate();

    printf("%d %d", c, r);
}

compiles the calculate() function into
calculate():
        lds r24,a
        lds r22,b
        rcall __udivmodqi4
        sts c,r24
        sts r,r25
        ret

The results, stored in r24 and r25 respectively, are re-used from the same division operation.

61410: <p>When I write code like this:</p>
<pre><code>int a = 7
int b = 2
int c = a/b
int r = a%b
</code></pre>
<p>Does the chip use the remainder while calculating c or does it redo the entire calculation?</p>
 23644: <p>The compiler is only as smart as you provide it the necessary information.</p>
<ol>
<li>It is good to examine code on godbolt.com. But use it wisely.<br />
Noone should ever compile without optimizations. In the example above the code is not optimized and thus would never been used as such on a board.</li>
<li>The example is so artificial that the compiler optimizes it away into just 2 instructions. So the code should be representative for the intended usage.<br />
A better godbolt would be:</li>
</ol>
<pre><code>#include&lt;stdint.h&gt;
#include&lt;stdlib.h&gt;

void myDiv(uint8_t * c, uint8_t * r, const uint8_t a, const uint8_t b) {
    *c = a/b;
    *r = a%b;
}
</code></pre>
<p>So the input is not predetermined and also the resulting numbers are returned and not thrown away. Which translates with <code>-Os</code> to:</p>
<pre><code>myDiv(unsigned char*, unsigned char*, unsigned char, unsigned char):
        mov r27,r25
        mov r26,r24
        mov r31,r23
        mov r30,r22
        mov r24,r20
        mov r22,r18
        rcall __udivmodqi4
        st X,r24
        st Z,r25
        ret
</code></pre>
<ol start="3">
<li>There is the <code>div(numerator, denominator)</code> function in <code>stdlib.h</code>. This function performs a division and returns both the dividend and the remainder. It is optimized for each platform and uses the best available method to get both. In Godbolt it would look like this:</li>
</ol>
<pre><code>#include&lt;stdint.h&gt;
#include&lt;stdlib.h&gt;

void myDiv2(uint8_t * c, uint8_t * r, const uint8_t a, const uint8_t b) {
    div_t d = div(a, b);
    *c = d.quot;
    *r = d.rem;
}

</code></pre>
<p>But what surprise, with <code>-Os</code> the resulting assembly looks exactly the same! (I leave it to the reader to try it on godbolt).</p>
<p>That means, the compiler is smart enough to:</p>
<p>a. recognise the intention when calling division and modulo an the same operands successively.<br />
b. will use the best available method to achieve the intended calculation for you.</p>
<hr />
<p><strong>EDIT after Edgar Bonet's comment:</strong><br />
While playing around in godbolt I made a copy-paste mistake. <code>div</code> only applies to <code>int</code> values. That makes the resulting assembly code larger as there has twice the data to be shoveld around. After changing both examples to <code>int</code> they look almost similar. The only difference is:</p>
<p>The result is stored in <code>d</code> first and then copied to <code>c</code> and <code>r</code>.<br />
So the division/modulo code is more efficient in that regard as the resulting values are copied directly from the registers used in the calling convention.</p>
<p><a href="https://godbolt.org/z/61exz7" rel="nofollow noreferrer">https://godbolt.org/z/61exz7</a></p>
 50183: <p>If using optimization, the compiler is smart enough to recognize this.</p>
<p>Since your example is so short, it could be optimized away entirely.
To ensure that doesn't happen, the results in <code>c</code> and <code>r</code> have to be used in some way.
Also, if <code>a</code> and <code>b</code> could <em>never</em> change, the values of <code>c</code> and <code>r</code> would be calculated during compilation.
Therefore, I put the calculation in its own function.</p>
<p>From <a href="https://godbolt.org/z/bG4cG6" rel="nofollow noreferrer">godbolt.com</a>, using AVR-GCC 9.2.0:</p>
<pre><code>#include&lt;stdint.h&gt;
#include&lt;stdio.h&gt;

uint8_t a = 0;
uint8_t b = 2;
uint8_t c = 0;
uint8_t r = 0;

void calculate() {
    c = a / b;
    r = a % b;
}

int main() {
    a = 7;
    b = 2;

    calculate();

    printf(&quot;%d %d&quot;, c, r);
}
</code></pre>
<p>compiles the <code>calculate()</code> function into</p>
<pre><code>calculate():
        lds r24,a
        lds r22,b
        rcall __udivmodqi4
        sts c,r24
        sts r,r25
        ret
</code></pre>
<p>The results, stored in <code>r24</code> and <code>r25</code> respectively, are re-used from the same division operation.</p>
