def gps_to_utc(gpssec):
    """
    Convert GPS seconds to UTC seconds.

    Parameters
    ----------
    gpssec: int
      Time in GPS seconds.

    Returns
    -------
    Time in UTC seconds.

    Notes
    -----
    The code is ported from Offline.

    Examples
    --------
    >>> gps_to_utc(0) # Jan 6th, 1980
    315964800
    """

    kSecPerDay = 24 * 3600
    kUTCGPSOffset0 = (10 * 365 + 7) * kSecPerDay

    kLeapSecondList = (
        ((361 + 0 * 365 + 0 + 181) * kSecPerDay + 0, 1),  # 1 JUL 1981
        ((361 + 1 * 365 + 0 + 181) * kSecPerDay + 1, 2),  # 1 JUL 1982
        ((361 + 2 * 365 + 0 + 181) * kSecPerDay + 2, 3),  # 1 JUL 1983
        ((361 + 4 * 365 + 1 + 181) * kSecPerDay + 3, 4),  # 1 JUL 1985
        ((361 + 7 * 365 + 1) * kSecPerDay + 4, 5),  # 1 JAN 1988
        ((361 + 9 * 365 + 2) * kSecPerDay + 5, 6),  # 1 JAN 1990
        ((361 + 10 * 365 + 2) * kSecPerDay + 6, 7),  # 1 JAN 1991
        ((361 + 11 * 365 + 3 + 181) * kSecPerDay + 7, 8),  # 1 JUL 1992
        ((361 + 12 * 365 + 3 + 181) * kSecPerDay + 8, 9),  # 1 JUL 1993
        ((361 + 13 * 365 + 3 + 181) * kSecPerDay + 9, 10),  # 1 JUL 1994
        ((361 + 15 * 365 + 3) * kSecPerDay + 10, 11),  # 1 JAN 1996
        ((361 + 16 * 365 + 4 + 181) * kSecPerDay + 11, 12),  # 1 JUL 1997
        ((361 + 18 * 365 + 4) * kSecPerDay + 12, 13),  # 1 JAN 1999
        # DV: 2000 IS a leap year since it is divisible by 400,
        #     ie leap years here are 2000 and 2004 -> leap days = 6
        ((361 + 25 * 365 + 6) * kSecPerDay + 13, 14),  # 1 JAN 2006
        ((361 + 28 * 365 + 7) * kSecPerDay + 14, 15),  # 1 JAN 2009
        ((361 + 31 * 365 + 8 + 181) * kSecPerDay + 15, 16),  # 1 JUL 2012
        ((361 + 34 * 365 + 8 + 181) * kSecPerDay + 16, 17),  # 1 JUL 2015
        ((361 + 36 * 365 + 9) * kSecPerDay + 17, 18)  # 1 JAN 2017
    )

    leapSeconds = 0
    for x in reversed(kLeapSecondList):
        if gpssec >= x[0]:
            leapSeconds = x[1]
            break

    return gpssec + kUTCGPSOffset0 - leapSeconds