In an earlier post -
Medications for high-altitude illness? - well-known high-altitude medical researchers Peter Hackett and Robert Roach reported that prophylactic aspirin (325 mg every four hours for a total of three doses) reduced the incidence of altitude headache from 50 percent to 7 percent. And, for treatment, a single dose of 400 mg or 600 mg of ibuprofen ameliorated or resolved high-altitude headaches.
There's a lot more in that thread and in their paper, but you specifically mentioned these drugs, so that's what I addressed.
Aspirin for prevention, ibuprofen for treatment.