def extract_function(lines):
    """Extract function code starting at first line of lines."""
    n = len(lines)
    begin = 0
    body_begin = begin
    body_end = n
    for i in range(begin, n):
        if '{' in lines[i]:
            body_begin = i
            break
    braces = 0
    for i in range(body_begin, n):
        if '{' in lines[i]:
            braces += 1
        if '}' in lines[i]:
            braces -= 1
        if braces == 0:
            body_end = i
            break
    end = body_end + 1
    sublines = lines[begin:end]
    return ''.join(sublines)
