How does any map have a "pseudosection" (assuming axiom of choice)? In the Lawvere and Rosebrugh book, Sets for Mathematics, exercise 4.34 is to show that the following is equivalent to the axiom of choice (every epimap has a section aka right inverse):

If $f:X\to Y$ is any mapping, provided $X$ is nonempty, there exists $g:Y\to X$ for which $fgf = f$.

(They say $g$ is "somewhat less than a section" and call it a "pseudosection" about a page later.)
I'd like to understand how to derive this from the axiom of choice (and vice versa). Maybe some finite colimits would be used, since this is in the chapter on colimits. Mapping sets should not be needed since they are introduced in the next chapter.
Is every such $f$ related to some specific epimap that can be used as a starting point? Or what does one do? I'm just an amateur. This particular exercise has worried me for a long time. I haven't found (or recognized) any directly relevant information, including during writing this question.
Edit: The book uses this construction to get an image factorization of a map, so I'm worried about just taking for granted that the image of $f$ is available as a map. Though I understand from my web searches that that does not require the axiom of choice - all toposes and many more categories have that? - so maybe it would work?

Afterthought: I decided to stop worrying and accept that I'm supposed to assume image factorization for this exercise. I'll pursue images separately on their own right.
Perhaps I should have included the full statement of the exercise:

Exercise 4.34 Show that the principle just enunciated is equivalent to the axiom of choice. (What do you need to assume about the category to prove this equivalence?) $\diamond$

I didn't mention that parenthesis originally.
 A: Try replacing $Y$ by the image of $f$; and extend the section you get by any means necessary (here the fact $X$ is nonempty plays a role).
I'm not sure how to cast this in category theoretic terms. But the idea that you can factor $f$ via restricting the codomain, and then use the axiom of choice.
A: I think I have to accept that I'm supposed to assume image factorization in the catefory instead of deriving it from the pseudosection (or derive image factorization from more fundamental axioms: the nLab page on regular categories seems promising). Then the order of presentation in the book seems funny to me but strictly speaking what they say after the exercise is only that $f = f\circ g\circ f$ can be used to  derive properties of image factorization, and perhaps that is so.
So I assume that $f$ has an image factorization, $m\circ e = f$, where $M$ has to be non-empty because $X$ is non-empty:
$$
X\xrightarrow{e \text{ (epic)}} M\xrightarrow{m\text{ (monic)}} Y
$$
Then it's easy to derive the required pseudosection.
First, $e$ has a section by the axiom of choice, and $m$ has a retraction because all non-empty monomaps have retractions (in the category of abstract sets anyway):
$$
X\xleftarrow{s \text{ (section of $e$)}}
M\xleftarrow{r \text{ (retraction of $m$)}} Y
$$
Composing $s$ on the right of the image factorization $m\circ e=f$ gives $m = f\circ s$. Composing $r$ on the left gives $e = r\circ f$. Substituting these back to $f = m\circ e$ gives $f = f\circ s\circ r\circ f$, and there is the desired pseudosection $g$ for which $f = f\circ g\circ f$:
$$
g = s\circ r
$$
This required that $f$ can be factored as a mono of an epi, which I'll pursue separately through that nLab page, and I think I'll leave the other direction of the exercise for later.
