// Vulnerability label: locked
pragma solidity ^0.4.23;

contract CSC {
    mapping (address => uint256) private balances;
    mapping (address => uint256[2]) private lockedBalances;
    string public name;                   //fancy name: eg Simon Bucks
    uint8 public decimals;                //How many decimals to show.
    string public symbol;                 //An identifier: eg SBX
    uint256 public totalSupply;
    address public owner;
        uint256 private icoLockUntil = 1543593540;
    event Transfer(address indexed _from, address indexed _to, uint256 _value); 
    constructor(
        uint256 _initialAmount,
        string _tokenName,
        uint8 _decimalUnits,
        string _tokenSymbol,
        address _owner,
        address[] _lockedAddress,
        uint256[] _lockedBalances,
        uint256[] _lockedTimes
    ) public {
        balances[_owner] = _initialAmount;                   // Give the owner all initial tokens
        totalSupply = _initialAmount;                        // Update total supply
        name = _tokenName;                                   // Set the name for display purposes
        decimals = _decimalUnits;                            // Amount of decimals for display purposes
        symbol = _tokenSymbol;                               // Set the symbol for display purposes
        owner = _owner;                                      // set owner
        for(uint i = 0;i < _lockedAddress.length;i++){
            lockedBalances[_lockedAddress[i]][0] = _lockedBalances[i];
            lockedBalances[_lockedAddress[i]][1] = _lockedTimes[i];
        }
    }
    /*å¤é¨ç´æåç©ºæ
     */
    /*è½¬è´¦ ä¼æ£æµæ¯å¦æéä»éé¢åæé
     */
    function transfer(address _to, uint256 _value) public returns (bool success) {
        //å½ICOæªå®ææ¶ï¼é¤ownerå¤ç¦æ­¢è½¬è´¦
        require(msg.sender == owner || icoLockUntil < now);
        if(_to != address(0)){
            if(lockedBalances[msg.sender][1] >= now) {
                require((balances[msg.sender] > lockedBalances[msg.sender][0]) &&
                 (balances[msg.sender] - lockedBalances[msg.sender][0] >= _value));
            } else {
                require(balances[msg.sender] >= _value);
            }
            balances[msg.sender] -= _value;
            balances[_to] += _value;
            emit Transfer(msg.sender, _to, _value);
            return true;
        }
    }
    /*ä»æå°åæ§æ¯ææ°éçä»£å¸å¹¶åå°æ»ä¾åºé éè¦æ¥æèæé
     */
    function burnFrom(address _who,uint256 _value)public returns (bool){
        require(msg.sender == owner);
        assert(balances[_who] >= _value);
        totalSupply -= _value;
        balances[_who] -= _value;
        lockedBalances[_who][0] = 0;
        lockedBalances[_who][1] = 0;
        return true;
    }
    /*é¸å¸å°åå§èè´¦æ·å¹¶å¢å æ»ä¾åºé éè¦æ¥æèæé
     */
    function makeCoin(uint256 _value)public returns (bool){
        require(msg.sender == owner);
        totalSupply += _value;
        balances[owner] += _value;
        return true;
    }
    /*è®¾ç½®ICOéä»å°ææ¶é´ï¼éè¦æ¥æç®¡çèæé
     */
    function setIcoLockUntil(uint256 _until) public{
        require(msg.sender == owner);
        icoLockUntil = _until;
    }
    function balanceOf(address _owner) public view returns (uint256 balance) {
        return balances[_owner];
    }
    /*å°åçº¦ä¸­çETHæåå°åå§èå°åä¸­ éæ±æ¥æèæé
     */
    function withdraw() public{
        require(msg.sender == owner);
        msg.sender.transfer(address(this).balance);
    }
    /*å°åçº¦ä¸­çETHæåå°æä¸ªå°åä¸­ éæ±æ¥æèæé
     */
    function withdrawTo(address _to) public{
        require(msg.sender == owner);
        address(_to).transfer(address(this).balance);
    }
}