is_gaussian_prime(z)? Task
Write a function that accepts two integers \$a,b\$ that represent the Gaussian integer \$z = a+bi\$ (complex number). The program must return true or false depending on whether \$a+bi\$ is a Gaussian prime or not.
Definition
\$a+bi\$ is a Gaussian prime if and only if it meets one of the following conditions:

\$a\$ and \$b\$ are both nonzero and \$a^2 + b^2\$ is prime
\$a\$ is zero, \$|b|\$ is prime and \$|b| = 3 \text{ (mod }4)\$
\$b\$ is zero, \$|a|\$ is prime and \$|a| = 3 \text{ (mod }4)\$

Details
You should only write a function. If your language does not have functions, you can assume that the integers are stored in two variables and print the result or write it to a file.
You cannot use built-in functions of your language like isprime or prime_list or nthprime or factor. The lowest number of bytes wins. The program must work for \$a,b\$ where \$a^2+b^2\$ is a 32bit (signed) integer and should finish in not significantly more than 30 seconds.
Prime list
The dots represent prime numbers on the Gaussian plane (x = real, y = imaginary axis):

Some larger primes:
(9940, 43833)
(4190, 42741)
(9557, 41412)
(1437, 44090)
C, 149 118 characters

Edited version (118 characters):

int G(int a,int b){a=abs(a);b=abs(b);int n=a*b?a*a+b*b:a+b,
d=2;for(;n/d/d&amp;&amp;n%d;d++);return n/d/d|n&lt;2?0:(a+b&amp;3)&gt;2|a*b;}


This is a single function:


G(a,b) returns nonzero (true) if a+bi is a Gaussian prime, or zero (false) otherwise.


It folds the integer primality test into an expression n/d/d|n&lt;2 hidden in the return value calculation. This golfed code also makes use of a*b as a substitute for a&amp;&amp;b (in other words a!=0 &amp;&amp; b!=0) and other tricks involving operator precedence and integer division. For example n/d/d is a shorter way of saying n/d/d&gt;=1, which is an overflow-safe way of saying n&gt;=d*d or d*d&lt;=n or in essence d&lt;=sqrt(n).



Original version (149 characters):

int Q(int n){int d=2;for(;n/d/d&amp;&amp;n%d;d++);return n/d/d||n&lt;2;}
int G(int a,int b){a=abs(a);b=abs(b);return!((a|b%4&lt;3|Q(b))*(b|a%4&lt;3|Q(a))*Q(a*a+b*b));}


Functions:


Q(n) returns 0 (false) if n is prime, or 1 (true) if n is nonprime. It is a helper function for G(a,b).
G(a,b) returns 1 (true) if a+bi is a Gaussian prime, or 0 (false) otherwise.


Sample output (scaled up 200%) for |a|,|b| ≤ 128: