Section Loop.
Variable (A : Type) (f : A -> A) (p : A -> bool).
Fixpoint loop (a : A) (k : nat) {struct k} :=
if p a then Some a else
match k with
| O => None
| S k' => loop (f a) k'
end.

Lemma loop_0 k a :
p a = true ->
loop a k = Some a.