else loop will be executed for (n-1) times
g(x) is also executed for (n-1) times as after every else g(x) should be executed. for better understanding draw the tree for some smaller input
again g(int m) function is executed for (1+logx) times
time complexity wil be (n-1)(n-1)(1+logx) = O(n^2) where (1+log x) can be omitted because of smaller value.
If I am wrong then plz correct me