Ltac non_wandQ_sep_conjunct_rec P :=
match P with
| ?Q * ?R =>
let res1 := non_wandQ_sep_conjunct_rec Q in
match res1 with
| Some _ => res1
| _ => non_wandQ_sep_conjunct_rec R
end
| allp _ =>
constr:(@None mpred)
| _ => constr:(Some P)
end.
Ltac non_wandQ_sep_conjunct P :=
let res := non_wandQ_sep_conjunct_rec P in
match res with
| Some ?Q => Q
| _ => emp
end.

Lemma wandQ_elim_alg2: forall {A} (P: A -> mpred) Q Q' RHS R a,
P a |-- Q -* R a ->
R a * Q' |-- RHS ->
allp P * (Q * Q') |-- RHS.