<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def generate_new_cid(upstream_cid=None):
 """Generate a new correlation id, possibly based on the given one."""

    if upstream_cid is None:
        return str(uuid.uuid4()) if getattr(settings, 'CID_GENERATE', False) else None
    if (
            getattr(settings, 'CID_CONCATENATE_IDS', False)
            and getattr(settings, 'CID_GENERATE', False)
    ):
        return '%s, %s' % (upstream_cid, str(uuid.uuid4()))
    return upstream_cid