'Differrent results in different compilers c++

I have created the following program:

#include <iostream>

int main(){
    int a,b,mod, a1,b1;
    std::cin >> a >> b;

    if(a >= b){
        mod = a % b;
    } else {
        mod = b % a;
    }

    
    if(mod == 0){
        std::cout << a;
    } else {
        while(a1 != 0 && b1 != 0){

        a1 = a % mod;
        b1 = b % mod;
        --mod;
    }
    std::cout << mod + 1;

}
   
    return 0;
}

I have tested with the following input: 25 27 and got result 1 (as expected). But in another compiler I got result 3 and unfortunately I don't have an access to testing with another compiler(only the final result). I don't know why and where the behaviour of my program is inconsistent.

c++


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source