```python
def sum(a, b):
    """
    Calculates the sum of common divisors of two given numbers.

    Args:
        a: The first integer.
        b: The second integer.

    Returns:
        The sum of all common divisors of a and b.
    """
    total_sum = 0
    # Iterate from 1 up to the minimum of the two numbers
    for i in range(1, min(a, b) + 1):
        # Check if i is a divisor for both a and b
        if a % i == 0 and b % i == 0:
            total_sum += i
    return total_sum

```