Factor Graph Optimization of Error-Correcting Codes for Belief Propagation Decoding