Does first law contradicts 2nd law of themodynamics? We can write first law of thermodynamics in two forms. $$dU=TdS-pdV$$ and $$dU=dq+dw$$ It is also true that $dw=-pdV$ therefore $TdS=dq$ for every process irrespective of reversibility. What I am missing here?
 A: It is true, for all processes whether reversible or not, that:
$$dU=TdS-PdV=dq+dw$$
as long as two of the four variables ($T, S, V, P$) can be defined for the system.  
However, it is not true that $dq = T dS$ always; that equality only holds for reversible processes.  Likewise, $dw = -PdV$ is only true for reversible processes.  If the processes is irreversible, then $dq \lt T dS$ and $dw \gt -PdV$. 
Nevertheless, because of the first law, the sum of $dq$ and $dw$ always equals the change in energy, whether the process is reversible or not:
$$dU=dq_\textrm{rev}+dw_\textrm{rev} = dq_\textrm{irrev}+dw_\textrm{irrev}$$
which also is equal to $TdS-PdV$.
A: No, dw = -pdV is ONLY for a reversible process and hence you can compare your two equations only if both are written for reversible processes  for which TdS = dq. What you are doing wrong is comparing an equation which holds for all processes with an equation that is true only for reversible processes. That is why you are getting a contradiction 
