<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def gfm(text):
 """ Prepare text for rendering by a regular Markdown processor. """

    def indent_code(matchobj):
        syntax = matchobj.group(1)
        code = matchobj.group(2)
        if syntax:
            result = '    :::' + syntax + '\n'
        else:
            result = ''
        # The last line will be blank since it had the closing "```". Discard it
        # when indenting the lines.
        return result + '\n'.join(['    ' + line for line in code.split('\n')[:-1]])

    use_crlf = text.find('\r') != -1
    if use_crlf:
        text = text.replace('\r\n', '\n')

    # Render GitHub-style ```code blocks``` into Markdown-style 4-space indented blocks
    text = CODEPATTERN_RE.sub(indent_code, text)

    text, code_blocks = remove_pre_blocks(text)
    text, inline_blocks = remove_inline_code_blocks(text)

    # Prevent foo_bar_baz from ending up with an italic word in the middle.
    def italic_callback(matchobj):
        s = matchobj.group(0)
        # don't mess with URLs:
        if 'http:' in s or 'https:' in s:
            return s

        return s.replace('_', r'\_')

    # fix italics for code blocks
    text = ITALICSPATTERN_RE.sub(italic_callback, text)

    # linkify naked URLs
    # wrap the URL in brackets: http://foo -> [http://foo](http://foo)
    text = NAKEDURL_RE.sub(r'\1[\2](\2)\3', text)

    # In very clear cases, let newlines become <br /> tags.
    def newline_callback(matchobj):
        if len(matchobj.group(1)) == 1:
            return matchobj.group(0).rstrip() + '  \n'
        else:
            return matchobj.group(0)

    text = NEWLINE_RE.sub(newline_callback, text)

    # now restore removed code blocks
    removed_blocks = code_blocks + inline_blocks
    for removed_block in removed_blocks:
        text = text.replace('{placeholder}', removed_block, 1)

    if use_crlf:
        text = text.replace('\n', '\r\n')

    return text