Write a chicken interpreter! You have to write an interpreter for a cool language called Chicken!

You should read a Chicken program from a file, standard input, program or function arguments, or whatever is most convenient for your language, as well as input to the program. 

You should print or return the result of interpreting the program according to the Chicken language specification.

More description about the language.



Chicken Program Overview

Chicken operates on a single stack, which composes its entire memory model. As instructions are executed, the program will push and pop values from the stack, but there are also instructions that allow the program to modify other parts of the stack at will.

There are three segments in the stack:


The registers, at indices 0 and 1. Index 0 is a reference to the stack itself, and index 1 is a reference to the user input. Mostly used for instruction 6 (see below).
The loaded code: for each line of code there is cell in this segment that contains the number of "chicken"s in the line. This is padded with a 0 (opcode for terminate program) at the end.
The actual program stack, where values are pushed/popped as the program runs. Note that the segments are not isolated, which means that it is possible to create self-modifying code or execute code from this segment of the stack space.


The Chicken ISA

Chicken's instruction set is based around the number of times the word "chicken" appears on each line of the program. An empty line terminates the program and prints the topmost value in the stack.

The Chicken instruction set, by number of "chicken"s per line:


Push the literal string "chicken" to the stack
Add top two stack values as natural numbers and push the result.
Subtract top two values as natural numbers and push the result.
Multiply top two values as natural numbers and push the result.
Compare two top values for equality, push 1 if they are equal and 0 otherwise.
Look at the next instruction to determine which source to load from: 0 loads from stack, 1 loads from user input. Top of stack points to address/index to load from the given source; load that value and push it onto stack. Since this is a double wide instruction, the instruction pointer skips the instruction used to determine the source.
Top of stack points to address/index to store to. The value below that will be popped and stored in the stack at the given index.
Top of stack is a relative offset to jump to. If the value below that is truthy, then the program jumps by the offset.
Interprets the top of the stack as ascii and pushes the corresponding character.
(10 + N) Pushes the literal number n-10 onto the stack.




Example

Assume the program is:

chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken
chicken chicken chicken chicken chicken chicken
(an empty line)


(A cat program. Note that the empty line is required because of the preceding line having 6 "chicken".)

Input provided to Chicken program

Chicken


Output

Chicken


The Chicken.js reference implementation.



Error detection

The interpreter should leave an error and terminate when any word not "chicken" is present in the source.



Good luck!
Javascript ES6, 398 bytes
By far the longest golf I have ever done, I'm sure this can be improved but my brain doesn't recognize anything other than chicken at this point.
(a,b)=&gt;{for(c='chicken',s=[j=0,b,...A=a.split`
`.map(m=&gt;m.split(c).length-1)],i=A.length+2;j&lt;A.length;([_=&gt;s[++i]=c,_=&gt;s[--i]=s[i]+s[i+1],_=&gt;s[--i]=s[i]-s[i+1],_=&gt;s[--i]=s[i]*s[i+1],_=&gt;s[--i]=s[i]==s[i+1],_=&gt;s[i]=s[2+j++]?b[s[i]]:s[s[i]],_=&gt;s[s[i--]]=s[i--],_=&gt;j+=s[--i]?s[--i+2]:0,_=&gt;s[i]=String.fromCharCode(s[i])][s[j+2]-1]||(_=&gt;s[++i]=s[j+1]-10))(j++));return /[^chicken \n]\w/g.test(a)?0:s[i]}

I will edit the explanation in when my brain starts functioning again. Here's a slightly ungolfed version for now.
Outputs a falsey value (0) for everything which isn't chicken
(a,b)=&gt;{
    for(c='chicken',s=[j=0,b,...A=a.split`
    `.map(m=&gt;m.split(c).length-1)],i=A.length+2; // loop init
    j&lt;A.length; // loop condition
    ( // everything else
        [
            _=&gt;s[++i]=c,
            _=&gt;s[--i]=s[i]+s[i+1],
            _=&gt;s[--i]=s[i]-s[i+1],
            _=&gt;s[--i]=s[i]*s[i+1],
            _=&gt;s[--i]=s[i]==s[i+1],
            _=&gt;s[i]=s[2+j++]?b[s[i]]:s[s[i]],
            _=&gt;s[s[i--]]=s[i--],
            _=&gt;j+=s[--i]?s[--i+2]:0,
            _=&gt;s[i]=String.fromCharCode(s[i])
        ][s[j+2]-1]
        ||(_=&gt;s[++i]=s[j+1]-10)
    )(j++)
);
return /[^chicken \n]\w/g.test(a)?0:s[i]}

Try it here


f=
  (a,b)=&gt;{for(c='chicken',s=[j=0,b,...A=a.split`
`.map(m=&gt;m.split(c).length-1)],i=A.length+2;j&lt;A.length;([_=&gt;s[++i]=c,_=&gt;s[--i]=s[i]+s[i+1],_=&gt;s[--i]=s[i]-s[i+1],_=&gt;s[--i]=s[i]*s[i+1],_=&gt;s[--i]=s[i]==s[i+1],_=&gt;s[i]=s[2+j++]?b[s[i]]:s[s[i]],_=&gt;s[s[i--]]=s[i--],_=&gt;j+=s[--i]?s[--i+2]:0,_=&gt;s[i]=String.fromCharCode(s[i])][s[j+2]-1]||(_=&gt;s[++i]=s[j+1]-10))(j++));return /[^chicken \n]\w/g.test(a)?0:s[i]}

i.innerHTML = f(`chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken
chicken chicken chicken chicken chicken chicken
`, 'Hello world!')
&lt;pre id=i&gt;