It is performing multi-precision addition with carry propagation. The a
and b
arguments are pointers to multi-precision integers with n
digits each. In this case, the digits are 32-bits. The least-significant digits are in the lowest array indices.
The inputs are added, and the result is placed into the array pointed to by r
(also containing n
32-bit digits). It works by adding a digit from a
to a digit from b
with the carry-in c
, which is initialized to zero. A carry out is detected when the resulting digit is less than one of the input digits, or is equal to one of the digits when the carry-in is 1. The return value is the carry-out from the whole operation.
Imagine we are adding with base-10 digits. If we compute 9+9+0 mod 10, we get 8. Since 8 is less than 9, we infer that there must have been a carry-out. If we compute 9+9+1 modulo 10, we get 9; we infer a carry-out because the carry-in was set. If we compute 9+0+0, we get 9, but there was no carry-out because carry-in was 0.