compiler shows wrong answer even though program works

Hello. I am new to this site so please forgive any newbie mistakes I made, but why is the compiler showing me “Wrong Answer”, even though my code is right. What might be wrong?

Here is my code:

    int main()
    	int T,M,B;
    		scanf("%d %d",&M,&B);
    		while(B > 0)
    			if(M == B)
    			M = (M > B)?(M-B):((B = (B-M))+(2*M));
    		printf("%d\n", (M+B));
    	return 0;
*Note:* Before modifying to this, I used if-else but it was showing Time Limit Exceed. And this code runs fine on my gcc compiler (version same as in codechef).

well…the gcc 6.3 in codechef website successfully compiled the code, but the output that the code produced was not the correct answer, that’s why it states it as wrong answer.
the output should be 12
your code printed 9
and because your code doesn’t output the correct stuff, it becomes WA
edit : kudos for formatting the code as well