; SimpleStore (uint)

; Set the inital value of 42
sstore(0, 42)

; Init code to deploy myContract
codecopy(0, $myContract, #myContract)
return(0, #myContract)

@myContract {
    ; Non-payable
    jumpi($error, callvalue)

    ; Get the Sighash
    shr({{= 256 - 32 }}, calldataload(0))

    ; getValue()
    dup1
    {{= sighash("getValue()") }}
    jumpi($getValue, eq)

    ; setValue(uint)
    dup1
    {{= sighash("setValue(uint)") }}
    jumpi($setValue, eq)

    ; No matching signature
    @error:
        revert(0, 0)

    @getValue:
        mstore(0, sload(0))
        return (0, 32)

    @setValue:
        ; Make sure we have exactly a uint
        jumpi($error, iszero(eq(calldatasize, 36)))

        ; Store the value
        sstore(0, calldataload(4))
        return (0, 0)

    ; There is no *need* for the PUSH32, it just makes
    ; decompiled code look nicer
    @checksum[
        {{= (defines.checksum ? concat([ Opcode.from("PUSH32"), id(myContract.source) ]): "0x") }}
    ]
}
