Funny, if you swap the order of the operands in the multiplication, GCC 7.0 with -O3 does optimize it away:
int retNum(int num, int num2) {
return (num2 * num)/num;
}
now becomes retNum(int, int):
mov eax, esi
ret