It has been fairly well proven that heavy pot smoking can damage the lungs, so I hope that when you say you don’t smoke, you are referring to all smoking. Sometimes when people quit smoking, they cough more and raise more phlegm, which is often discolored. It usually happens within a month or so after quitting. That may be what is happening now. That kind of cough and sputum eventually clears up but can last 6 months or more. There is also the possibility that you have an acute infection, bronchitis or even pneumonia. You are wise to be getting an x-ray to make sure that any immediate therapy is warranted.
The pain you describe sounds like you have inflammation of the cartilage at the ends of a couple of ribs. The rib bone turns to cartilage and that attaches to the sternum. Coughing hard can cause it to become inflamed and painful. Medicines like ibuprofen can help to quell the inflammation and reduce the pain.
It is actually reasonable to assume that the brown phlegm is not an indication of a more serious lung condition such as cancer or an abscess.