\begin{tikzpicture}[circuit logic US, scale=0.8]

%Kompatibilita mezi babel a TIKZ |-
\shorthandoff{-}

  \def\N{3}
  \def\POLYNOM{0,1,0}

%  \newcounter{cnt}
  \setcounter{cnt}{0}
  \newcounter{poscnt}

  \def\prev{0}

  %Construct LFSR counter
  \foreach \m in \POLYNOM{
    \addtocounter{cnt}{1}
    \addtocounter{poscnt}{1}

    \ifthenelse{\equal{\m}{0}}{
    %Only DFLOP
      \node [shape=dff] (DFF\thecnt) at ($2*(\theposcnt,0)$) {};

      \ifthenelse{\equal{\thecnt}{1}}{
      %First flop
  
        %Feedback path 
        \path (DFF1) +(1cm, -1.5cm) coordinate (fbk);        %Point on common line
        \draw [-] (DFF1.D) -- +(-10mm, 0) |- (fbk);
      }{
      %Ordinary flop
        \draw [-] (DFF\prev.Q) -- (DFF\thecnt.D);
      }
    }{
    %XOR + DFLOP
      \node [xor gate, inputs={nn}, point right] (XOR\thecnt) at ($(DFF\prev.Q)+2*(0.75,0)$) {};
      \draw [-] (DFF\prev.Q) -- +(2.5mm,0) |-  (XOR\thecnt.input 1);
      \draw [-] (XOR\thecnt.input 2) -- +(-5mm, 0) |- (fbk);
      \addtocounter{poscnt}{1}

      \node [shape=dff] (DFF\thecnt) at ($2*(\theposcnt,0)$) {}; 
      \draw [-] (XOR\thecnt.output) -- (DFF\thecnt.D);
      
    }
    \global\edef\prev{\thecnt}
  }


  %Feedback path 
  \draw [-] (DFF\thecnt.Q) -| +(5mm, -20mm) |- (fbk); %Line from last DFF
  

  % Clock port 
  \path (DFF1) +(-3cm,-2.5cm) coordinate (temp)
    node [anchor=east] {clock};
  \foreach \m in {1,...,\N}
    \draw [-] (temp) -| ($ (DFF\m.CLK) + (-5mm,0) $) --(DFF\m.CLK);


\end{tikzpicture}
