The liver normally filters out ammonia, which is a toxic by-product from the break down of protein that we eat, but when the liver is too damaged it can't do that anymore, and the ammonia
ends up in your blood
goes to your brain, where it causes mental symptoms. That's hepatic encephalopathy, which is a complication of advanced cirrhosis. Lactulose is the standard treatment, it binds to the ammonia in the body and makes it pass through the intestines.