lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.25
/*
 * @dev Buy tokens from incoming funds
 */
function buy(address referrer) public payable {

        // apply fee
        (uint fee_funds, uint taxed_funds) = fee_purchase.split(msg.value);
        require(fee_funds != 0, "Incoming funds is too small");

        // update user's referrer
        //  - you cannot be a referrer for yourself
        //  - user and his referrer will be together all the life
        UserRecord storage user = user_data[msg.sender];
        if (referrer != 0x0 && referrer != msg.sender && user.referrer == 0x0) {
            user.referrer = referrer;
        }

        // apply referral bonus
        if (user.referrer != 0x0) {
            fee_funds = rewardReferrer(msg.sender, user.referrer, fee_funds, msg.value);
            require(fee_funds != 0, "Incoming funds is too small");
        }

        // calculate amount of tokens and change price
        (uint tokens, uint _price) = fundsToTokens(taxed_funds);
        require(tokens != 0, "Incoming funds is too small");
        price = _price;

        // mint tokens and increase shared profit
        mintTokens(msg.sender, tokens);
        shared_profit = shared_profit.add(fee_funds);

        emit Purchase(msg.sender, msg.value, tokens, price / precision_factor, now);
    }
// Solidity 0.4.25
/*
 * @dev Sell given amount of tokens and get funds
 */
function sell(uint tokens) public onlyValidTokenAmount(tokens) {

        // calculate amount of funds and change price
        (uint funds, uint _price) = tokensToFunds(tokens);
        require(funds != 0, "Insufficient tokens to do that");
        price = _price;

        // apply fee
        (uint fee_funds, uint taxed_funds) = fee_selling.split(funds);
        require(fee_funds != 0, "Insufficient tokens to do that");

        // burn tokens and add funds to user's dividends
        burnTokens(msg.sender, tokens);
        UserRecord storage user = user_data[msg.sender];
        user.gained_funds = user.gained_funds.add(taxed_funds);

        // increase shared profit
        shared_profit = shared_profit.add(fee_funds);

        emit Selling(msg.sender, tokens, funds, price / precision_factor, now);
    }
// Solidity 0.4.25
/*
 * @dev Transfer given amount of tokens from sender to another user
 * ERC20
 */
function transfer(address to_addr, uint tokens) public onlyValidTokenAmount(tokens) returns (bool success) {

        require(to_addr != msg.sender, "You cannot transfer tokens to yourself");

        // apply fee
        (uint fee_tokens, uint taxed_tokens) = fee_transfer.split(tokens);
        require(fee_tokens != 0, "Insufficient tokens to do that");

        // calculate amount of funds and change price
        (uint funds, uint _price) = tokensToFunds(fee_tokens);
        require(funds != 0, "Insufficient tokens to do that");
        price = _price;

        // burn and mint tokens excluding fee
        burnTokens(msg.sender, tokens);
        mintTokens(to_addr, taxed_tokens);

        // increase shared profit
        shared_profit = shared_profit.add(funds);

        emit Transfer(msg.sender, to_addr, tokens);
        return true;
    }
// Solidity 0.4.25
/*
 * @dev Reinvest all dividends
 */
function reinvest() public {

        // get all dividends
        uint funds = dividendsOf(msg.sender);
        require(funds > 0, "You have no dividends");

        // make correction, dividents will be 0 after that
        UserRecord storage user = user_data[msg.sender];
        user.funds_correction = user.funds_correction.add(int(funds));

        // apply fee
        (uint fee_funds, uint taxed_funds) = fee_purchase.split(funds);
        require(fee_funds != 0, "Insufficient dividends to do that");

        // apply referral bonus
        if (user.referrer != 0x0) {
            fee_funds = rewardReferrer(msg.sender, user.referrer, fee_funds, funds);
            require(fee_funds != 0, "Insufficient dividends to do that");
        }

        // calculate amount of tokens and change price
        (uint tokens, uint _price) = fundsToTokens(taxed_funds);
        require(tokens != 0, "Insufficient dividends to do that");
        price = _price;

        // mint tokens and increase shared profit
        mintTokens(msg.sender, tokens);
        shared_profit = shared_profit.add(fee_funds);

        emit Reinvestment(msg.sender, funds, tokens, price / precision_factor, now);
    }
// Solidity 0.4.25
/*
 * @dev Withdraw all dividends
 */
function withdraw() public {

        // get all dividends
        uint funds = dividendsOf(msg.sender);
        require(funds > 0, "You have no dividends");

        // make correction, dividents will be 0 after that
        UserRecord storage user = user_data[msg.sender];
        user.funds_correction = user.funds_correction.add(int(funds));

        // send funds
        msg.sender.transfer(funds);

        emit Withdrawal(msg.sender, funds, now);
    }
// Solidity 0.4.25
/*
 * @dev Amount of user's dividends
 */
function dividendsOf(address addr) public view returns (uint) {

        UserRecord memory user = user_data[addr];

        // gained funds from selling tokens + bonus funds from referrals
        // int because "user.funds_correction" can be negative
        int d = int(user.gained_funds.add(user.ref_funds));
        require(d >= 0);

        // avoid zero divizion
        if (total_supply > 0) {
            // profit is proportional to stake
            d = d.add(int(shared_profit.mul(user.tokens) / total_supply));
        }

        // correction
        // d -= user.funds_correction
        if (user.funds_correction > 0) {
            d = d.sub(user.funds_correction);
        }
        else if (user.funds_correction < 0) {
            d = d.add(-user.funds_correction);
        }

        // just in case
        require(d >= 0);

        // total sum must be positive uint
        return uint(d);
    }
// Solidity 0.4.25
/*
 * @dev Amount of tokens can be gained from given amount of funds
 */
function expectedTokens(uint funds, bool apply_fee) public view returns (uint) {
        if (funds == 0) {
            return 0;
        }
        if (apply_fee) {
            (,uint _funds) = fee_purchase.split(funds);
            funds = _funds;
        }
        (uint tokens,) = fundsToTokens(funds);
        return tokens;
    }
// Solidity 0.4.25
/*
 * @dev Mint given amount of tokens to given user
 */
function mintTokens(address addr, uint tokens) internal {

        UserRecord storage user = user_data[addr];

        bool not_first_minting = total_supply > 0;

        // make correction to keep dividends the rest of the users
        if (not_first_minting) {
            shared_profit = shared_profit.mul(total_supply.add(tokens)) / total_supply;
        }

        // add tokens
        total_supply = total_supply.add(tokens);
        user.tokens = user.tokens.add(tokens);

        // make correction to keep dividends of user
        if (not_first_minting) {
            user.funds_correction = user.funds_correction.add(int(tokens.mul(shared_profit) / total_supply));
        }
    }
// Solidity 0.4.25
/*
 * @dev Burn given amout of tokens from given user
 */
function burnTokens(address addr, uint tokens) internal {

        UserRecord storage user = user_data[addr];

        // keep current dividents of user if last tokens will be burned
        uint dividends_from_tokens = 0;
        if (total_supply == tokens) {
            dividends_from_tokens = shared_profit.mul(user.tokens) / total_supply;
        }

        // make correction to keep dividends the rest of the users
        shared_profit = shared_profit.mul(total_supply.sub(tokens)) / total_supply;

        // sub tokens
        total_supply = total_supply.sub(tokens);
        user.tokens = user.tokens.sub(tokens);

        // make correction to keep dividends of the user
        // if burned not last tokens
        if (total_supply > 0) {
            user.funds_correction = user.funds_correction.sub(int(tokens.mul(shared_profit) / total_supply));
        }
        // if burned last tokens
        else if (dividends_from_tokens != 0) {
            user.funds_correction = user.funds_correction.sub(int(dividends_from_tokens));
        }
    }
// Solidity 0.4.25
/*
 * @dev Rewards the referrer from given amount of funds
 */
function rewardReferrer(address addr, address referrer_addr, uint funds, uint full_funds) internal returns (uint funds_after_reward) {
        UserRecord storage referrer = user_data[referrer_addr];
        if (referrer.tokens >= minimal_stake) {
            (uint reward_funds, uint taxed_funds) = fee_referral.split(funds);
            referrer.ref_funds = referrer.ref_funds.add(reward_funds);
            emit ReferralReward(addr, referrer_addr, full_funds, reward_funds, now);
            return taxed_funds;
        }
        else {
            return funds;
        }
    }
// Solidity 0.4.25
/*
 * @dev Calculate tokens from funds
 *
 * Given:
 *   a[1] = price
 *   d = price_offset
 *   sum(n) = funds
 * Here is used arithmetic progression's equation transformed to a quadratic equation:
 *   a * n^2 + b * n + c = 0
 * Where:
 *   a = d
 *   b = 2 * a[1] - d
 *   c = -2 * sum(n)
 * Solve it and first root is what we need - amount of tokens
 * So:
 *   tokens = n
 *   price = a[n+1]
 *
 * For details see method below
 */
function fundsToTokens(uint funds) internal view returns (uint tokens, uint _price) {
        uint b = price.mul(2).sub(price_offset);
        uint D = b.mul(b).add(price_offset.mul(8).mul(funds).mul(precision_factor));
        uint n = D.sqrt().sub(b).mul(precision_factor) / price_offset.mul(2);
        uint anp1 = price.add(price_offset.mul(n) / precision_factor);
        return (n, anp1);
    }
// Solidity 0.4.25
/*
 * @dev Calculate funds from tokens
 *
 * Given:
 *   a[1] = sell_price
 *   d = price_offset
 *   n = tokens
 * Here is used arithmetic progression's equation (-d because of d must be negative to reduce price):
 *   a[n] = a[1] - d * (n - 1)
 *   sum(n) = (a[1] + a[n]) * n / 2
 * So:
 *   funds = sum(n)
 *   price = a[n]
 *
 * For details see method above
 */
function tokensToFunds(uint tokens) internal view returns (uint funds, uint _price) {
        uint sell_price = price.sub(price_offset);
        uint an = sell_price.add(price_offset).sub(price_offset.mul(tokens) / precision_factor);
        uint sn = sell_price.add(an).mul(tokens) / precision_factor.mul(2);
        return (sn / precision_factor, an);
    }
// Solidity 0.4.25
/**
 * @dev Multiplies two numbers
 */
function mul(uint a, uint b) internal pure returns (uint) {
        if (a == 0) {
            return 0;
        }
        uint c = a * b;
        require(c / a == b, "mul failed");
        return c;
    }
// Solidity 0.4.25
/**
 * @dev Gives square root from number
 */
function sqrt(uint x) internal pure returns (uint y) {
        uint z = add(x, 1) / 2;
        y = x;
        while (z < y) {
            y = z;
            z = add(x / z, z) / 2;
        }
    }
// Solidity 0.4.25
/*
 * @dev Splits given value to two parts: tax itself and taxed value
 */
function split(fee memory f, uint value) internal pure returns (uint tax, uint taxed_value) {
        if (value == 0) {
            return (0, 0);
        }
        tax = value.mul(f.num) / f.den;
        taxed_value = value.sub(tax);
    }
// Solidity 0.6.11
/* Gets 1-f^t    where: f < 1
 
 f: issuance factor that determines the shape of the curve
 t:  time passed since last LQTY issuance event  */
function _getCumulativeIssuanceFraction() internal view returns (uint) {
        // Get the time passed since deployment
        uint timePassedInMinutes = block.timestamp.sub(deploymentTime).div(SECONDS_IN_ONE_MINUTE);

        // f^t
        uint power = LiquityMath._decPow(ISSUANCE_FACTOR, timePassedInMinutes);

        //  (1 - f^t)
        uint cumulativeIssuanceFraction = (uint(DECIMAL_PRECISION).sub(power));
        assert(cumulativeIssuanceFraction <= DECIMAL_PRECISION); // must be in range [0,1]

        return cumulativeIssuanceFraction;
    }
// Solidity 0.6.2
/// @notice Used by Certifying Authorities to change their wallet (in case of theft).
///   Migrating prevents any new certificate registrations signed by the old wallet.
///   Already registered certificates would be valid.
/// @param _newAuthorityAddress Next wallet address of the same certifying authority
function migrateCertifyingAuthority(
    address _newAuthorityAddress
  ) public onlyAuthorisedCertifier {
    require(
      certifyingAuthorities[_newAuthorityAddress].status == AuthorityStatus.NotAuthorised
      , 'cannot migrate to an already authorised address'
    );

    certifyingAuthorities[msg.sender].status = AuthorityStatus.Migrated;
    emit AuthorityStatusUpdated(msg.sender, AuthorityStatus.Migrated);

    certifyingAuthorities[_newAuthorityAddress] = CertifyingAuthority({
      data: certifyingAuthorities[msg.sender].data,
      status: AuthorityStatus.Authorised
    });
    emit AuthorityStatusUpdated(_newAuthorityAddress, AuthorityStatus.Authorised);

    emit AuthorityMigrated(msg.sender, _newAuthorityAddress);
  }
// Solidity 0.6.2
/// @notice Used to check whether an address exists in packed addresses bytes
/// @param _signer Address of the signer wallet
/// @param _packedSigners Bytes string of addressed packed together
/// @return boolean value which means if _signer doesnot exist in _packedSigners bytes string
function _checkUniqueSigner(
    address _signer,
    bytes memory _packedSigners
  ) private pure returns (bool){
    if(_packedSigners.length == 0) return true;

    require(_packedSigners.length % 20 == 0, 'invalid packed signers length');

    address _tempSigner;
    /// @notice loop through every packed signer and check if signer exists in the packed signers
    for(uint256 i = 0; i < _packedSigners.length; i += 20) {
      assembly {
        _tempSigner := mload(add(_packedSigners, add(0x14, i)))
      }
      if(_tempSigner == _signer) return false;
    }

    return true;
  }
// Solidity 0.6.2
/// @notice Used to get a number's utf8 representation
/// @param i Integer
/// @return utf8 representation of i
function _getBytesStr(uint i) private pure returns (bytes memory) {
    if (i == 0) {
      return "0";
    }
    uint j = i;
    uint len;
    while (j != 0) {
      len++;
      j /= 10;
    }
    bytes memory bstr = new bytes(len);
    uint k = len - 1;
    while (i != 0) {
      bstr[k--] = byte(uint8(48 + i % 10));
      i /= 10;
    }
    return bstr;
  }
// Solidity 0.4.8
/* Send coins from the caller's account */
function transfer(address _to, uint256 _value) public {
		if (_to == 0x0) throw; // Prevent transfer to 0x0 address. Use burn() instead 
		if (_value <= 0) throw;
		if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
		if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows 
		balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
		balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); // Add the same to the recipient
		Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
	}
// Solidity 0.4.8
/* Send coins from an account that previously approved this caller to do so */
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
		if (_to == 0x0) throw; // Prevent transfer to 0x0 address. Use burn() instead
		if (_value <= 0) throw;
		if (balanceOf[_from] < _value) throw; // Check if the sender has enough 
		if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
		if (_value > allowance[_from][msg.sender]) throw; // Check allowance 
		balanceOf[_from] = SafeMath.safeSub(balanceOf[_from], _value); // Subtract from the sender
		balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); // Add the same to the recipient
		allowance[_from][msg.sender] = SafeMath.safeSub(allowance[_from][msg.sender], _value); 
		Transfer(_from, _to, _value); // emit event
		return true;
	}
// Solidity 0.4.8
/* Permanently delete some number of coins that are in the caller's account */
function burn(uint256 _value) public returns (bool success) {
		if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
		if (_value <= 0) throw;
		balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
		totalSupply = SafeMath.safeSub(totalSupply,_value); // Reduce the total supply too
		Burn(msg.sender, _value); // emit event
		return true;
	}
// Solidity 0.4.8
/* Make some of the caller's coins temporarily unavailable */
function freeze(uint256 _value) public returns (bool success) {
		if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
		if (_value <= 0) throw;
		balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
		freezeOf[msg.sender] = SafeMath.safeAdd(freezeOf[msg.sender], _value); // Add to sender's frozen balance
		Freeze(msg.sender, _value); // emit event
		return true;
	}
// Solidity 0.4.8
/* Frozen coins can be made available again by unfreezing them */
function unfreeze(uint256 _value) public returns (bool success) {
		if (freezeOf[msg.sender] < _value) throw; // Check if the sender has enough
		if (_value <= 0) throw;
		freezeOf[msg.sender] = SafeMath.safeSub(freezeOf[msg.sender], _value); // Subtract from sender's frozen balance
		balanceOf[msg.sender] = SafeMath.safeAdd(balanceOf[msg.sender], _value); // Add to the sender
		Unfreeze(msg.sender, _value); // emit event
		return true; 
	}
// Solidity 0.4.18
/*
 Attempt to purchase the tokens from the token contract.
 This must be done before the sale ends
 
 */
function buyTokens() external onlyWhenRefundsNotEnabled onlyWhenTokensNotPurchased onlyOwner {
        require(this.balance >= totalPresale);

        tokenContract.buyTokens.value(this.balance)();
        //Get the exchange rate the contract will got for the purchase. Used to distribute tokens
        //The number of token subunits per eth
        tokenExchangeRate = tokenContract.getCurrentPrice(this);
        
        tokensPurchased = true;

        LogTokenPurchase(totalPresale, tokenContract.tokenSaleBalanceOf(this));
    }
// Solidity 0.4.18
/*
 Transfer an accounts token entitlement to itself.
 This can only be called if the tokens have been purchased by the contract and have been withdrawn by the contract.
 */
function withdrawTokens() external onlyWhenSyndicateTokensWithdrawn {
        uint256 tokens = SafeMath.div(SafeMath.mul(presaleBalances[msg.sender], tokenExchangeRate), 1 ether);
        assert(tokens > 0);

        totalPresale = SafeMath.sub(totalPresale, presaleBalances[msg.sender]);
        presaleBalances[msg.sender] = 0;

        /*
           Attempt to transfer tokens to msg.sender.
           Note: we are relying on the token contract to return a success bool (true for success). If this
           bool is not implemented as expected it may be possible for an account to withdraw more tokens than
           it is entitled to.
        */
        assert(tokenContract.transfer( msg.sender, tokens));
        LogWithdrawTokens(msg.sender, tokens);
    }
// Solidity 0.8.7
// Burn FRIES from account with approval
function burnFrom(address account, uint256 amount) external {
        uint256 currentAllowance = allowance(account, _msgSender());
        require(currentAllowance >= amount, "ERC20: burn amount exceeds allowance");
        unchecked {
            _approve(account, _msgSender(), currentAllowance - amount);
        }
        _burn(account, amount);
    }
// Solidity 0.6.2
/*
 * @param item RLP encoded list in bytes
 */
function toList(RLPItem memory item) internal pure returns (RLPItem[] memory) {
    require(isList(item));

    uint items = numItems(item);
    RLPItem[] memory result = new RLPItem[](items);

    uint memPtr = item.memPtr + _payloadOffset(item.memPtr);
    uint dataLen;
    for (uint i = 0; i < items; i++) {
      dataLen = _itemLength(memPtr);
      result[i] = RLPItem(dataLen, memPtr);
      memPtr = memPtr + dataLen;
    }

    return result;
  }
// Solidity 0.6.2
// @return indicator whether encoded payload is a list. negate this function call for isData.
function isList(RLPItem memory item) internal pure returns (bool) {
    if(item.len == 0) return false;

    uint8 byte0;
    uint memPtr = item.memPtr;
    assembly {
      byte0 := byte(0, mload(memPtr))
    }

    if(byte0 < LIST_SHORT_START) return false;

    return true;
  }
// Solidity 0.6.2
// @returns raw rlp encoding in bytes
function toRlpBytes(RLPItem memory item) internal pure returns (bytes memory) {
    bytes memory result = new bytes(item.len);
    if (result.length == 0) return result;

    uint ptr;
    assembly {
      ptr := add(0x20, result)
    }

    copy(item.memPtr, ptr, item.len);
    return result;
  }
// Solidity 0.6.2
// any non-zero byte is considered true
function toBoolean(RLPItem memory item) internal pure returns (bool) {
    require(item.len == 1);
    uint result;
    uint memPtr = item.memPtr;
    assembly {
      result := byte(0, mload(memPtr))
    }

    return result == 0 ? false : true;
  }
// Solidity 0.6.2
// enforces 32 byte length
function toUintStrict(RLPItem memory item) internal pure returns (uint) {
    // one byte prefix
    require(item.len == 33);

    uint result;
    uint memPtr = item.memPtr + 1;
    assembly {
      result := mload(memPtr)
    }

    return result;
  }
// Solidity 0.6.2
// @return number of payload items inside an encoded list.
function numItems(RLPItem memory item) private pure returns (uint) {
    if (item.len == 0) return 0;

    uint count = 0;
    uint currPtr = item.memPtr + _payloadOffset(item.memPtr);
    uint endPtr = item.memPtr + item.len;
    while (currPtr < endPtr) {
      currPtr = currPtr + _itemLength(currPtr); // skip over an item
      count++;
    }

    return count;
  }
// Solidity 0.6.2
// @return entire rlp item byte length
function _itemLength(uint memPtr) private pure returns (uint) {
    uint itemLen;
    uint byte0;
    assembly {
      byte0 := byte(0, mload(memPtr))
    }

    if (byte0 < STRING_SHORT_START)
      itemLen = 1;

    else if (byte0 < STRING_LONG_START)
      itemLen = byte0 - STRING_SHORT_START + 1;

    else if (byte0 < LIST_SHORT_START) {
      assembly {
        let byteLen := sub(byte0, 0xb7) // # of bytes the actual length is
        memPtr := add(memPtr, 1) // skip over the first byte

        /* 32 byte word size */
        let dataLen := div(mload(memPtr), exp(256, sub(32, byteLen))) // right shifting to get the len
        itemLen := add(dataLen, add(byteLen, 1))
      }
    }

    else if (byte0 < LIST_LONG_START) {
      itemLen = byte0 - LIST_SHORT_START + 1;
    }

    else {
      assembly {
        let byteLen := sub(byte0, 0xf7)
        memPtr := add(memPtr, 1)

        let dataLen := div(mload(memPtr), exp(256, sub(32, byteLen))) // right shifting to the correct length
        itemLen := add(dataLen, add(byteLen, 1))
      }
    }

    return itemLen;
  }
// Solidity 0.6.2
// @return number of bytes until the data
function _payloadOffset(uint memPtr) private pure returns (uint) {
    uint byte0;
    assembly {
      byte0 := byte(0, mload(memPtr))
    }

    if (byte0 < STRING_SHORT_START)
      return 0;
    else if (byte0 < STRING_LONG_START || (byte0 >= LIST_SHORT_START && byte0 < LIST_LONG_START))
      return 1;
    else if (byte0 < LIST_SHORT_START)  // being explicit
      return byte0 - (STRING_LONG_START - 1) + 1;
    else
      return byte0 - (LIST_LONG_START - 1) + 1;
  }