conclude that the work done by friction or any opposing force in both the scenarios will be the same, then how can we say that we can get maximum work from a reversible process? Shouldn't both reversible and non-reversible process give the same result?
To address this, we introduce a concept known as entropy production (see here), so if have viscous forces or such, immediately we are speaking of an irreversible process which involves a lesser heat transfer into the system and more wastage. See here for the intuition behind it.
You can actually derive it from the Clausius inequality, first of all, consider two processes: Process-A and process-B, which ends up in the same final state. One is reversible and the other is irreversible both involving some infinitesimal heat and infinitesimal work moving from state-1 $\to$ state-2. Writing down the Clausius inequality for process-B:
$$ dS_{ 1 \to 2} \geq \frac{dq}{T}$$
For this process, we can write the entropy using the reversible process:
$$ dS_{1 \to 2} = \frac{dq_{rev} }{T}$$
Pluggin this, we reach:
$$ dq_{rev} \geq dq$$
Or,
$$ dq_{rev} - dq \geq 0 \tag{1}$$
Now, head back to the second law of thermodynamics:
$$ dU_{1 \to 2} = dq + dw = dq_{rev} + dw_{rev} \tag{2}$$
Since, quantities in thermodynamics are path independent , we can say that sum of infinitesimal heat transfer plus the infinitesimal work done should be same for both processes.
Rearranging eq-(2),
$$ dq_{rev} -dq= dw - dw_{rev}$$
Using (1) and (3),
$$dq_{rev} - dq = dw-dw_{rev} \geq 0$$
Or,
$$ dw \geq dw_{rev}$$
In the sign convention I'm using, work is negative when energy leaves the system and hence to make work done by system as positive, we multiply by a minus:
$$ - dw_{rev} \geq -dw$$
taking the modulus:
$$ |dw_{rev}| \geq | dw$$
Inspired from Atkin's physical chemistry, see page-81 bottom-most paragraph under section "The Clausius inequality"