The function f(x) takes a string as input and replaces the second occurrence of the letter 'l' with the letter 'g'.

[CODE]:
```python
def f(x):
    count = 0
    new_string = ""
    for char in x:
        if char == 'l':
            count += 1
            if count == 2:
                new_string += 'g'
            else:
                new_string += char
        else:
            new_string += char
    return new_string
```