Thirteen In Four Squarings

long long binpow(long long a, long long b, long long m) {
    long long res = 1;
    a %= m;
    while (b > 0) {
        if (b & 1) res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

cout << binpow(3, 13, 1000);

What does this print, and how many times does the line res = res * a % m; execute?

A

243, and the line runs 2 times

B

323, and the line runs 3 times

C

323, and the line runs 4 times

D

561, and the line runs 3 times