I need a function that checks a condition; for example, if $a == $b
it should return the access denied page to the current user.
What function should I use?
I think you are looking for the function which returns the access denied page; that is drupal_access_denied(). Just call this function inside your conditional statement.