Submission 8bc886a0...

ChallengeBrainFuck interpreter
Submitterzac.creditmint.eth
Submitted at2018-31-30
Gas used353202
/**
 * This file is part of the 1st Solidity Gas Golfing Contest.
 *
 * This work is licensed under Creative Commons Attribution ShareAlike 3.0.
 * https://creativecommons.org/licenses/by-sa/3.0/
 */

pragma solidity ^0.4.23;

contract BrainFuck {
    /**
     * @dev Executes a BrainFuck program, as described at https://en.wikipedia.org/wiki/Brainfuck.
     *
     * Memory cells, input, and output values are all expected to be 8 bit
     * integers. Incrementing past 255 should overflow to 0, and decrementing
     * below 0 should overflow to 255.
     *
     * Programs and input streams may be of any length. The memory tape starts
     * at cell 0, and will never be moved below 0 or above 1023. No program will
     * output more than 1024 values.
     *
     * @return The program's output stream. Should be exactly the length of the
     *          number of outputs produced by the program.
     */
    function execute(bytes, bytes) external view returns(bytes) {
        // Here's a funny thing. One of the interesting idiosyncrasies of the EVM is how
        // it handles jump instructions. It takes the jump destination from the stack, as opposed to
        // most languages, where jump destinations are hardcoded defined at compile time instead of runtime.
        // This allows for interesting shenanigans! Like, for example, using a lookup table to alter the program flow :)
        // All things considered, I think this turned out rather well. Honestly I'm surprised it works at all...
        // Well, that's about it. I feel like annotating the code with any more comments would be against the
        // spirit of this category. It is, after all, called BrainFuck for a reason.
        assembly {
                0x24 calldataload has_data jumpi
                mstore(0x00, 0x20)
                mstore(0x20, 0x00)
                mstore(0x40, 0x00)
                return(0x00, 0x60)
                has_data:
                // sneaky gas expander. Sshhhh! We don't want to submit our best attempt yet...
                0x00
                0x00
                sneaky_gas_expander:
                    0 not dup3 dup3 mulmod swap2 pop        // i j
                    0x01 add
                    dup2 0x00 mstore
                    0x200 dup2 lt sneaky_gas_expander jumpi
                pop pop
                mstore(0x40, 0x60) //???
                mstore(0x00, 0x140)
                mstore(0x7c0, 0x20)
                mstore(0x780, 0x40)
                mstore(0x560, 0x60)
                mstore(0x5a0, 0x80)
                mstore(0x5c0, 0xa0)
                mstore(0x580, 0xc0)
                mstore(0xb60, 0xe0)
                mstore(0xba0, 0x100)

                mstore(0x1000, no_op)
                mstore(0x1020, c_increase_data_pointer)
                mstore(0x1040, c_decrease_data_pointer)
                mstore(0x1060, c_increase_data_cell)
                mstore(0x1080, c_decrease_data_cell)
                mstore(0x10a0, c_output_data_cell)
                mstore(0x10c0, c_load_input)
                mstore(0x10e0, c_jump_forward)
                mstore(0x1100, c_jump_backward)
                mstore(0x1120, c_strike_slightly_more_sensible_faustian_bargain)
                mstore(0x1140, c_finish_compilation)

                mstore(0x1160, c_increase_data_pointer_then_no_op)
                mstore(0x1180, c_increase_data_pointer_twice)
                mstore(0x11c0, c_increase_data_pointer_then_increase_data_cell)
                mstore(0x11e0, c_increase_data_pointer_then_decrease_data_cell)
                mstore(0x1200, c_increase_data_pointer_then_output_data_cell)
                mstore(0x1220, c_increase_data_pointer_then_load_input)
                mstore(0x1240, c_increase_data_pointer_then_jump_forward)
                mstore(0x1260, c_increase_data_pointer_then_jump_backward)
                mstore(0x1280, c_increase_data_pointer_then_strike_faustian_bargain)
                mstore(0x12a0, c_increase_data_pointer_then_finish_compilation)

                mstore(0x12c0, c_increase_data_pointer_many_then_no_op)
                mstore(0x12e0, c_increase_data_pointer_many_again)
                mstore(0x1320, c_increase_data_pointer_many_then_increase_data_cell)
                mstore(0x1340, c_increase_data_pointer_many_then_decrease_data_cell)
                mstore(0x1360, c_increase_data_pointer_many_then_output_data_cell)
                mstore(0x1380, c_increase_data_pointer_many_then_load_input)
                mstore(0x13a0, c_increase_data_pointer_many_then_jump_forward)
                mstore(0x13c0, c_increase_data_pointer_many_then_jump_backward)
                mstore(0x13e0, c_increase_data_pointer_many_then_strike_faustian_bargain)
                mstore(0x1400, c_increase_data_pointer_many_then_finish_compilation)

                mstore(0x1420, c_decrease_data_pointer_then_no_op)
                mstore(0x1460, c_decrease_data_pointer_twice)
                mstore(0x1480, c_decrease_data_pointer_then_increase_data_cell)
                mstore(0x14a0, c_decrease_data_pointer_then_decrease_data_cell)
                mstore(0x14c0, c_decrease_data_pointer_then_output_data_cell)
                mstore(0x14e0, c_decrease_data_pointer_then_load_input)
                mstore(0x1500, c_decrease_data_pointer_then_jump_forward)
                mstore(0x1520, c_decrease_data_pointer_then_jump_backward)
                mstore(0x1540, c_decrease_data_pointer_then_strike_faustian_bargain)
                mstore(0x1560, c_decrease_data_pointer_then_finish_compilation)

                mstore(0x1580, c_decrease_data_pointer_many_then_no_op)
                mstore(0x15c0, c_decrease_data_pointer_many_again)
                mstore(0x15e0, c_decrease_data_pointer_many_then_increase_data_cell)
                mstore(0x1600, c_decrease_data_pointer_many_then_decrease_data_cell)
                mstore(0x1620, c_decrease_data_pointer_many_then_output_data_cell)
                mstore(0x1640, c_decrease_data_pointer_many_then_load_input)
                mstore(0x1660, c_decrease_data_pointer_many_then_jump_forward)
                mstore(0x1680, c_decrease_data_pointer_many_then_jump_backward)
                mstore(0x16a0, c_decrease_data_pointer_many_then_strike_faustian_bargain)
                mstore(0x16c0, c_decrease_data_pointer_many_then_finish_compilation)

                mstore(0x16e0, c_increase_data_cell_then_no_op)
                mstore(0x1700, c_increase_data_cell_then_increase_data_pointer)
                mstore(0x1720, c_increase_data_cell_then_decrease_data_pointer)
                mstore(0x1740, c_increase_data_cell_twice)
                mstore(0x1780, c_increase_data_cell_then_output_data_cell)
                mstore(0x17a0, c_increase_data_cell_then_load_input)
                mstore(0x17c0, c_increase_data_cell_then_jump_forward)
                mstore(0x17e0, c_increase_data_cell_then_jump_backward)
                mstore(0x1800, c_increase_data_cell_then_strike_faustian_bargain)
                mstore(0x1820, c_increase_data_cell_then_finish_compilation)

                mstore(0x1840, c_decrease_data_cell_then_no_op)
                mstore(0x1860, c_decrease_data_cell_then_increase_data_pointer)
                mstore(0x1880, c_decrease_data_cell_then_decrease_data_pointer)
                mstore(0x18c0, c_decrease_data_cell_twice)
                mstore(0x18e0, c_decrease_data_cell_then_output_data_cell)
                mstore(0x1900, c_decrease_data_cell_then_load_input)
                mstore(0x1920, c_decrease_data_cell_then_jump_forward)
                mstore(0x1940, c_decrease_data_cell_then_jump_backward)
                mstore(0x1960, c_decrease_data_cell_then_strike_faustian_bargain)
                mstore(0x1980, c_decrease_data_cell_then_finish_compilation)

                mstore(0x19a0, c_output_data_cell_then_no_op)
                mstore(0x19c0, c_output_data_cell_then_increase_data_pointer)
                mstore(0x19e0, c_output_data_cell_then_decrease_data_pointer)
                mstore(0x1a00, c_output_data_cell_then_increase_data_cell)
                mstore(0x1a20, c_output_data_cell_then_decrease_data_cell)
                mstore(0x1a40, c_output_data_cell_twice)
                mstore(0x1a60, c_output_data_cell_then_load_input)
                mstore(0x1a80, c_output_data_cell_then_jump_forward)
                mstore(0x1aa0, c_output_data_cell_then_jump_backward)
                mstore(0x1ac0, c_output_data_cell_then_strike_faustian_bargain)
                mstore(0x1ae0, c_output_data_cell_then_finish_compilation)

                mstore(0x1b00, c_load_input_then_no_op)
                mstore(0x1b20, c_load_input_then_increase_data_pointer)
                mstore(0x1b40, c_load_input_then_decrease_data_pointer)
                mstore(0x1b60, c_load_input_then_increase_data_cell)
                mstore(0x1b80, c_load_input_then_decrease_data_cell)
                mstore(0x1ba0, c_load_input_then_output_data_cell)
                mstore(0x1bc0, c_load_input_twice)
                mstore(0x1be0, c_load_input_then_jump_forward)
                mstore(0x1c00, c_load_input_then_jump_backward)
                mstore(0x1c20, c_load_input_then_strike_faustian_bargain)
                mstore(0x1c40, c_load_input_then_finish_compilation)

                mstore(0x1c80, 0x120)

                // general stack state: list of variables that represent indices in lookup table that
                // maps to jump endpoints

                // each subroutine pushes a status flag onto the stack before jumping
                // the status flag is combined with the lookup table index to create a final lookup index
                0x44
                c_strike_slightly_more_sensible_faustian_bargain: // uh oh...
                0x1000
                strike_faustian_bargain:    // I have come to bargain...
                    0x1c60 mstore           // store status flag
                    0x20 add                // increase program counter
                    0x1c80                   // add strike_faustian_bargain index
                    dup2 calldataload
                    dup1 0 byte 0x20 mul 0xfc0 mstore
                    0x20 mul dup1 0xfe0 mstore
                    0x1fff and
                    0xfdf mload
                    0xfde mload
                    0xfdd mload
                    0xfdc mload
                    0xfdb mload
                    0xfda mload
                    0xfd9 mload
                    0xfd8 mload
                    0xfd7 mload
                    0xfd6 mload
                    0xfd5 mload
                    0xfd4 mload
                    0xfd3 mload
                    0xfd2 mload
                    0xfd1 mload
                    0xfd0 mload
                    0xfcf mload
                    0xfce mload
                    0xfcd mload
                    0xfcc mload
                    0xfcb mload
                    0xfca mload
                    0xfc9 mload
                    0xfc8 mload
                    0xfc7 mload
                    0xfc6 mload
                    0xfc5 mload
                    0xfc4 mload
                    0xfc3 mload
                    0xfc2 mload
                    0xfc0 mload
                    0x1c60 mload
                    swap1 0x1fe0 and mload add mload jump
                no_op:
                    0x1fe0 and mload 0x1000 add mload jump
                    
                0 1 2 3 4 5 8 9 1 2 3 9 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 10
                    // 0x1fe0 and mload no_op add jump
// increase data pointer then ... 0x160
// increase data pointer many then ... 0x2c0
// decrease data pointer then ... 0x420
// decrease data pointer many then ... 0x580
// increase data cell then ... 0x6e0
// decrease data cell then ... 0x840
// output data cell then ... 0x9a0
// load input then ... 0xb00
                c_increase_data_pointer:
                    0x1fe0 and mload 0x1160 add mload jump
                c_decrease_data_pointer:
                    0x1fe0 and mload 0x1420 add mload jump
                c_increase_data_cell:
                    0x1fe0 and mload 0x16e0 add mload jump
                c_decrease_data_cell:
                    0x1fe0 and mload 0x1840 add mload jump
                c_output_data_cell:
                    0x1fe0 and mload 0x19a0 add mload jump
                c_load_input:
                    0x1fe0 and mload 0x1b00 add mload jump
                c_jump_forward:
                    jump_forward msize mstore
                    0x40 mload msize dup2 mstore
                    0x20 add 0x40 mstore
                    gas msize mstore // hmmmmmmm
                    0x1fe0 and mload 0x1000 add mload jump
                c_jump_backward:
                    0x20 0x40 mload sub dup1 0x40 mstore mload
                    jump_backward msize mstore
                    0x20 dup2 add msize mstore
                    msize swap1 mstore
                    0x1fe0 and mload 0x1000 add mload jump   

                c_increase_data_pointer_then_no_op:
                    0x1fe0 and mload 0x1160 add mload jump
                c_increase_data_pointer_then_increase_data_cell:
                    increase_data_pointer_then_increase_data_cell msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_increase_data_pointer_then_decrease_data_cell:
                    increase_data_pointer_then_decrease_data_cell msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_increase_data_pointer_twice:
                    0x2 msize 0x20 add mstore
                    0x1fe0 and mload 0x12c0 add mload jump
                c_increase_data_pointer_then_output_data_cell:
                    increase_data_pointer_then_output_data_cell msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_increase_data_pointer_then_load_input:
                    increase_data_pointer_then_load_input msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_increase_data_pointer_then_jump_forward:
                    increase_data_pointer_then_jump_forward msize mstore
                    0x40 mload msize dup2 mstore
                    0x20 add 0x40 mstore
                    gas msize mstore // hmmmmmmm
                    0x1fe0 and mload 0x1000 add mload jump
                c_increase_data_pointer_then_jump_backward:
                    0x20 0x40 mload sub dup1 0x40 mstore mload
                    increase_data_pointer_then_jump_backward msize mstore
                    0x20 dup2 add msize mstore
                    msize swap1 mstore
                    0x1fe0 and mload 0x1000 add mload jump 
                c_increase_data_pointer_then_strike_faustian_bargain:
                    0x1160 strike_faustian_bargain jump

                c_increase_data_pointer_many_then_no_op:
                    0x1fe0 and mload 0x12c0 add mload jump
                c_increase_data_pointer_many_then_increase_data_cell:
                    increase_data_pointer_many_then_increase_data_cell 0x40 msize sub mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_increase_data_pointer_many_then_decrease_data_cell:
                    increase_data_pointer_many_then_decrease_data_cell 0x40 msize sub mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_increase_data_pointer_many_again:
                    0x20 msize sub dup1 mload 0x1 add swap1 mstore
                    0x1fe0 and mload 0x12c0 add mload jump
                c_increase_data_pointer_many_then_decrease_data_pointer:
                    increase_data_pointer_many_then_decrease_data_pointer 0x40 msize sub mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_increase_data_pointer_many_then_output_data_cell:
                    increase_data_pointer_many_then_output_data_cell 0x40 msize sub mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_increase_data_pointer_many_then_load_input:
                    increase_data_pointer_many_then_load_input 0x40 msize sub mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_increase_data_pointer_many_then_jump_forward:
                    increase_data_pointer_many_then_jump_forward 0x40 msize sub mstore
                    0x40 mload msize dup2 mstore
                    0x20 add 0x40 mstore
                    gas msize mstore // hmmmmmmm
                    0x1fe0 and mload 0x1000 add mload jump
                c_increase_data_pointer_many_then_jump_backward:
                    0x20 0x40 mload sub dup1 0x40 mstore mload
                    increase_data_pointer_many_then_jump_backward 0x40 msize sub mstore
                    0x20 dup2 add msize mstore
                    msize swap1 mstore
                    0x1fe0 and mload 0x1000 add mload jump 
                c_increase_data_pointer_many_then_strike_faustian_bargain:
                    0x12c0 strike_faustian_bargain jump

///////
                c_decrease_data_pointer_then_no_op:
                    0x1fe0 and mload 0x1420 add mload jump
                c_decrease_data_pointer_then_increase_data_cell:
                    decrease_data_pointer_then_increase_data_cell msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_decrease_data_pointer_then_decrease_data_cell:
                    decrease_data_pointer_then_decrease_data_cell msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_decrease_data_pointer_twice:
                    0x2 msize 0x20 add mstore
                    0x1fe0 and mload 0x1580 add mload jump
                c_decrease_data_pointer_then_output_data_cell:
                    decrease_data_pointer_then_output_data_cell msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_decrease_data_pointer_then_load_input:
                    decrease_data_pointer_then_load_input msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_decrease_data_pointer_then_jump_forward:
                    decrease_data_pointer_then_jump_forward msize mstore
                    0x40 mload msize dup2 mstore
                    0x20 add 0x40 mstore
                    gas msize mstore // hmmmmmmm
                    0x1fe0 and mload 0x1000 add mload jump
                c_decrease_data_pointer_then_jump_backward:
                    0x20 0x40 mload sub dup1 0x40 mstore mload
                    decrease_data_pointer_then_jump_backward msize mstore
                    0x20 dup2 add msize mstore
                    msize swap1 mstore
                    0x1fe0 and mload 0x1000 add mload jump 
                c_decrease_data_pointer_then_strike_faustian_bargain:
                    0x1420 strike_faustian_bargain jump

                c_decrease_data_pointer_many_then_no_op:
                    0x1fe0 and mload 0x1580 add mload jump
                c_decrease_data_pointer_many_then_increase_data_pointer:
                    decrease_data_pointer_many_then_increase_data_pointer 0x40 msize sub mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_decrease_data_pointer_many_then_increase_data_cell:
                    decrease_data_pointer_many_then_increase_data_cell 0x40 msize sub mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_decrease_data_pointer_many_then_decrease_data_cell:
                    decrease_data_pointer_many_then_decrease_data_cell 0x40 msize sub mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_decrease_data_pointer_many_again:
                    0x20 msize sub dup1 mload 0x1 add swap1 mstore
                    0x1fe0 and mload 0x1580 add mload jump
                c_decrease_data_pointer_many_then_output_data_cell:
                    decrease_data_pointer_many_then_output_data_cell 0x40 msize sub mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_decrease_data_pointer_many_then_load_input:
                    decrease_data_pointer_many_then_load_input 0x40 msize sub mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_decrease_data_pointer_many_then_jump_forward:
                    decrease_data_pointer_many_then_jump_forward 0x40 msize sub mstore
                    0x40 mload msize dup2 mstore
                    0x20 add 0x40 mstore
                    gas msize mstore // hmmmmmmm
                    0x1fe0 and mload 0x1000 add mload jump
                c_decrease_data_pointer_many_then_jump_backward:
                    0x20 0x40 mload sub dup1 0x40 mstore mload
                    decrease_data_pointer_many_then_jump_backward 0x40 msize sub mstore
                    0x20 dup2 add msize mstore
                    msize swap1 mstore
                    0x1fe0 and mload 0x1000 add mload jump 
                c_decrease_data_pointer_many_then_strike_faustian_bargain:
                    0x1580 strike_faustian_bargain jump

                c_increase_data_cell_then_no_op:
                    0x1fe0 and mload 0x16e0 add mload jump
                c_increase_data_cell_then_increase_data_pointer:
                    increase_data_cell_then_increase_data_pointer msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_increase_data_cell_then_decrease_data_pointer:
                    increase_data_cell_then_decrease_data_pointer msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_increase_data_cell_twice:
                    increase_data_cell_twice msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_increase_data_cell_then_output_data_cell:
                    increase_data_cell_then_output_data_cell msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_increase_data_cell_then_load_input:
                    increase_data_cell_then_load_input msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_increase_data_cell_then_jump_forward:
                    increase_data_cell_then_jump_forward msize mstore
                    0x40 mload msize dup2 mstore
                    0x20 add 0x40 mstore
                    gas msize mstore // hmmmmmmm
                    0x1fe0 and mload 0x1000 add mload jump
                c_increase_data_cell_then_jump_backward:
                    0x20 0x40 mload sub dup1 0x40 mstore mload
                    increase_data_cell_then_jump_backward msize mstore
                    0x20 dup2 add msize mstore
                    msize swap1 mstore
                    0x1fe0 and mload 0x1000 add mload jump 
                c_increase_data_cell_then_strike_faustian_bargain:
                    0x16e0 strike_faustian_bargain jump

                c_decrease_data_cell_then_no_op:
                    0x1fe0 and mload 0x1840 add mload jump
                c_decrease_data_cell_then_increase_data_pointer:
                    decrease_data_cell_then_increase_data_pointer msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_decrease_data_cell_then_decrease_data_pointer:
                    decrease_data_cell_then_decrease_data_pointer msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_decrease_data_cell_twice:
                    decrease_data_cell_twice msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_decrease_data_cell_then_output_data_cell:
                    decrease_data_cell_then_output_data_cell msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_decrease_data_cell_then_load_input:
                    decrease_data_cell_then_load_input msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_decrease_data_cell_then_jump_forward:
                    decrease_data_cell_then_jump_forward msize mstore
                    0x40 mload msize dup2 mstore
                    0x20 add 0x40 mstore
                    gas msize mstore // hmmmmmmm
                    0x1fe0 and mload 0x1000 add mload jump
                c_decrease_data_cell_then_jump_backward:
                    0x20 0x40 mload sub dup1 0x40 mstore mload
                    decrease_data_cell_then_jump_backward msize mstore
                    0x20 dup2 add msize mstore
                    msize swap1 mstore
                    0x1fe0 and mload 0x1000 add mload jump 
                c_decrease_data_cell_then_strike_faustian_bargain:
                    0x1840 strike_faustian_bargain jump

                c_output_data_cell_then_no_op:
                    0x1fe0 and mload 0x19a0 add mload jump
                c_output_data_cell_then_increase_data_pointer:
                    output_data_cell_then_increase_data_pointer msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_output_data_cell_then_decrease_data_pointer:
                    output_data_cell_then_decrease_data_pointer msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_output_data_cell_then_increase_data_cell:
                    output_data_cell_then_increase_data_cell msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_output_data_cell_then_decrease_data_cell:
                    output_data_cell_then_decrease_data_cell msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_output_data_cell_twice:
                    output_data_cell_twice msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_output_data_cell_then_load_input:
                    output_data_cell_then_load_input msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_output_data_cell_then_jump_forward:
                    output_data_cell_then_jump_forward msize mstore
                    0x40 mload msize dup2 mstore
                    0x20 add 0x40 mstore
                    gas msize mstore // hmmmmmmm
                    0x1fe0 and mload 0x1000 add mload jump
                c_output_data_cell_then_jump_backward:
                    0x20 0x40 mload sub dup1 0x40 mstore mload
                    output_data_cell_then_jump_backward msize mstore
                    0x20 dup2 add msize mstore
                    msize swap1 mstore
                    0x1fe0 and mload 0x1000 add mload jump 
                c_output_data_cell_then_strike_faustian_bargain:
                    0x19a0 strike_faustian_bargain jump

                c_load_input_then_no_op:
                    0x1fe0 and mload 0x1b00 add mload jump
                c_load_input_then_increase_data_pointer:
                    load_input_then_increase_data_pointer msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_load_input_then_decrease_data_pointer:
                    load_input_then_decrease_data_pointer msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_load_input_then_increase_data_cell:
                    load_input_then_increase_data_cell msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_load_input_then_decrease_data_cell:
                    load_input_then_decrease_data_cell msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_load_input_twice:
                    load_input_twice msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_load_input_then_output_data_cell:
                    load_input_then_output_data_cell msize mstore
                    0x1fe0 and mload 0x1000 add mload jump
                c_load_input_then_jump_forward:
                    load_input_then_jump_forward msize mstore
                    0x40 mload msize dup2 mstore
                    0x20 add 0x40 mstore
                    gas msize mstore // hmmmmmmm
                    0x1fe0 and mload 0x1000 add mload jump
                c_load_input_then_jump_backward:
                    0x20 0x40 mload sub dup1 0x40 mstore mload
                    load_input_then_jump_backward msize mstore
                    0x20 dup2 add msize mstore
                    msize swap1 mstore
                    0x1fe0 and mload 0x1000 add mload jump 
                c_load_input_then_strike_faustian_bargain:
                    0x1b00 strike_faustian_bargain jump

                c_finish_compilation:
                    finish_execution msize mstore
                    act_II jump

                c_increase_data_pointer_then_finish_compilation:
                    finish_execution msize mstore
                    act_II jump

                c_increase_data_pointer_many_then_finish_compilation:
                    finish_execution 0x40 msize sub mstore
                    act_II jump
    
                c_decrease_data_pointer_then_finish_compilation:
                    finish_execution msize mstore
                    act_II jump

                c_decrease_data_pointer_many_then_finish_compilation:
                    finish_execution 0x40 msize sub mstore
                    act_II jump
    
                c_increase_data_cell_then_finish_compilation:
                    finish_execution msize mstore
                    act_II jump
                c_decrease_data_cell_then_finish_compilation:
                    finish_execution msize mstore
                    act_II jump

                c_load_input_then_finish_compilation:
                    finish_execution msize mstore
                    act_II jump

                c_output_data_cell_then_finish_compilation:
                    output_data_cell_then_finish_execution msize mstore
                    act_II jump

            /*        0x1b00 strike_faustian_bargain jump

                // > (0x3e * 0x20)
                compile_increment_data_pointer:
                    dup1 0x1fe0 and 0x7c0 eq compile_increment_data_pointer_many jumpi
                    increment_data_pointer msize mstore
                    0x1fe0 and mload no_op add jump
                compile_increment_data_pointer_many:
                    0x01
                compile_increment_data_pointer_many_loop:
                    swap1 pop 0x01 add
                    dup2 0x1fe0 and 0x7c0 eq compile_increment_data_pointer_many_loop jumpi
                    increment_data_pointer_many msize mstore
                    msize mstore
                    0x1fe0 and mload no_op add jump
                
                // <
                compile_decrement_data_pointer:
                    decrement_data_pointer msize mstore
                    0x1fe0 and mload no_op add jump

                // +
                compile_increment_data_cell:
                    increment_data_cell msize mstore
                    0x1fe0 and mload no_op add jump
                // -
                compile_decrement_data_cell:
                    decrement_data_cell msize mstore
                    0x1fe0 and mload no_op add jump

                // .
                compile_output_data_cell:
                    output_data_cell msize mstore
                    0x1fe0 and mload no_op add jump

                // ,
                compile_input_to_data_cell:
                    input_to_data_cell msize mstore
                    0x1fe0 and mload no_op add jump

                // [
                compile_conditional_jump_forward:
                    conditional_jump_forward msize mstore
                    0x40 mload msize dup2 mstore
                    0x20 add 0x40 mstore
                    gas msize mstore // hmmmmmmm
                    0x1fe0 and mload no_op add jump

                // ]
                compile_conditional_jump_backward:
                    0x20 0x40 mload sub dup1 0x40 mstore mload
                    conditional_jump_backward msize mstore
                    0x20 dup2 add msize mstore
                    msize swap1 mstore
                    0x1fe0 and mload no_op add jump    */


        act_II:
                // My old manager once told me that most programmers work hard but good
                // programmers are lazy, a quote I have often used when I feel like mixing
                // confirmation bias with questionable life choices.
                // Back to the point, I am so very lazy. Calculating a byte-offset that maps
                // the data pointer to the least significant byte in a word of memory every time
                // we operate on program memory, for example, is far too much work.
                // We can operate on the most significant byte instead, most of the time, and
                // scorn trifling concepts like static typing.
                // However there's a problem! Addition/subtraction requires adding/subtracting
                // 2^224. Now, I was merrily shoving these literals onto the stack like it's no big
                // thing but the 'optimizer' was replacing these with 'exp' opcodes! Exp! That thing
                // is outrageously expensive. Luckily this is one of the few places in the program
                // where I actually know the state of the stack, so throw the 'literals' on here and
                // duplicate them instead. So we don't pay that exp cost every time we execute
                // a brianfuck opcode -.-
                0x0100000000000000000000000000000000000000000000000000000000000000  // 1-ish
                0xff00000000000000000000000000000000000000000000000000000000000000  // ff-ish 1-ish
                dup2 dup1 add swap2                                                 // 1-ish ff-ish 2-ish
                // this one too... gets replaced with '0 NOT' :/
                0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
                0x05 0x24 calldataload add      // -1 1-ish ff-ish
                0x400
                0x120
                0x1ca0
                dup1 mload jump

/*
                increment_data_pointer:
                    swap1 0x01 add swap1
                    0x20 add dup1
                    mload jump

                increment_data_pointer_many:
                    swap1 dup2 0x20 add mload add swap1
                    0x40 add dup1
                    mload jump

                decrement_data_pointer:
                    0x01 dup3 sub swap2 pop
                    0x20 add dup1
                    mload jump

                increment_data_cell:
                    0x0100000000000000000000000000000000000000000000000000000000000000
                    dup3 mload add dup3 mstore
                    0x20 add dup1
                    mload jump

                decrement_data_cell:
                    0x0100000000000000000000000000000000000000000000000000000000000000
                    dup3 mload sub dup3 mstore
                    0x20 add dup1
                    mload jump

                output_data_cell:
                    dup2 mload dup4 0x01 add swap4 mstore
                    0x20 add dup1
                    mload jump

                input_to_data_cell:
                    dup4 0x01 add swap4 calldataload dup3 mstore8
                    0x20 add dup1
                    mload jump
    
                ternary_operator_rejects_explicit_politeness:
                    dup1 "please" eq finish_execution jumpi

                conditional_jump_forward:
                    0xff00000000000000000000000000000000000000000000000000000000000000
                    dup3 mload and skip_jump_forward jumpi
                    0x20 add mload dup1
                    mload jump
                skip_jump_forward:
                    0x40 add dup1
                    mload jump

                conditional_jump_backward:
                    0xff00000000000000000000000000000000000000000000000000000000000000
                    dup3 mload and jump_backward jumpi
                    0x40 add dup1
                    mload jump
                jump_backward:
                    0x20 add mload dup1
                    mload jump
*/

            increase_data_pointer_then_increase_data_cell:      // pc dp op ip -1
                swap1 0x01 add swap1
                dup6
                dup3 mload add dup3 mstore
                0x20 add dup1
                mload jump

            increase_data_pointer_then_decrease_data_cell:
                swap1 0x01 add swap1
                dup6
                dup3 mload sub dup3 mstore
                0x20 add dup1
                mload jump
            increase_data_pointer_then_output_data_cell:
                swap1 0x01 add swap1
                dup2 mload dup4 0x01 add swap4 mstore
                0x20 add dup1
                mload jump
            increase_data_pointer_then_load_input:
                swap1 0x01 add swap1
                dup4 0x01 add swap4 calldataload dup3 mstore8
                0x20 add dup1
                mload jump
            increase_data_pointer_then_jump_forward:
                swap1 0x01 add swap1
                dup7
                dup3 mload and skip_idp_jump_forward jumpi
                0x20 add mload dup1
                mload jump
                skip_idp_jump_forward:
                    0x40 add dup1
                    mload jump
            increase_data_pointer_then_jump_backward:
                swap1 0x01 add swap1
                dup7
                dup3 mload and skip_idp_jump_backward jumpi
                0x40 add dup1
                mload jump
                skip_idp_jump_backward:
                    0x20 add mload dup1
                    mload jump

            decrease_data_pointer_then_increase_data_cell:
                swap1 dup5 add swap1
                dup6
                dup3 mload add dup3 mstore
                0x20 add dup1
                mload jump

            decrease_data_pointer_then_decrease_data_cell:
                swap1 dup5 add swap1
                dup6
                dup3 mload sub dup3 mstore
                0x20 add dup1
                mload jump
            decrease_data_pointer_then_output_data_cell:
                swap1 dup5 add swap1
                dup2 mload dup4 0x01 add swap4 mstore
                0x20 add dup1
                mload jump
            decrease_data_pointer_then_load_input:
                swap1 dup5 add swap1
                dup4 0x01 add swap4 calldataload dup3 mstore8
                0x20 add dup1
                mload jump
            decrease_data_pointer_then_jump_forward:
                swap1 dup5 add swap1
                dup7
                dup3 mload and skip_ddp_jump_forward jumpi
                0x20 add mload dup1
                mload jump
                skip_ddp_jump_forward:
                    0x40 add dup1
                    mload jump
            decrease_data_pointer_then_jump_backward:
                swap1 dup5 add swap1
                dup7
                dup3 mload and skip_ddp_jump_backward jumpi
                0x40 add dup1
                mload jump
                skip_ddp_jump_backward:
                    0x20 add mload dup1
                    mload jump
            increase_data_pointer_many_then_decrease_data_pointer:
                swap1 0x01 dup3 0x20 add mload add sub swap1
                0x40 add dup1
                mload jump
            increase_data_pointer_many_then_increase_data_cell:      // pc dp op ip -1
                swap1 dup2 0x20 add mload add swap1
                dup6
                dup3 mload add dup3 mstore
                0x40 add dup1
                mload jump
            increase_data_pointer_many_then_decrease_data_cell:
                swap1 dup2 0x20 add mload add swap1
                dup6
                dup3 mload sub dup3 mstore
                0x40 add dup1
                mload jump
            increase_data_pointer_many_then_output_data_cell:
                swap1 dup2 0x20 add mload add swap1
                dup2 mload dup4 0x01 add swap4 mstore
                0x40 add dup1
                mload jump
            increase_data_pointer_many_then_load_input: // pc dp i o
                swap1 dup2 0x20 add mload               // <x> dp pc i o 
                add swap1                               // pc dp' i o
                dup4 0x01 add swap4 calldataload dup3 mstore8   // dp' <y> pc dp' i o
                0x40 add dup1
                mload jump
            increase_data_pointer_many_then_jump_forward:
                swap1 dup2 0x20 add mload add swap1
                dup7
                dup3 mload and skip_idpm_jump_forward jumpi
                0x40 add mload dup1
                mload jump
                skip_idpm_jump_forward:
                    0x60 add dup1
                    mload jump
            increase_data_pointer_many_then_jump_backward:
                swap1 dup2 0x20 add mload add swap1
                dup7
                dup3 mload and skip_idpm_jump_backward jumpi
                0x60 add dup1
                mload jump
                skip_idpm_jump_backward:
                    0x40 add mload dup1
                    mload jump

            decrease_data_pointer_many_then_increase_data_pointer:
                swap1 dup2 0x20 add mload swap1 sub 0x01 add swap1 // todo: optimize>
                0x40 add dup1
                mload jump
            decrease_data_pointer_many_then_increase_data_cell:      // pc dp op ip -1
                swap1 dup2 0x20 add mload swap1 sub swap1 // todo: optimize>
                dup6
                dup3 mload add dup3 mstore
                0x40 add dup1
                mload jump
            decrease_data_pointer_many_then_decrease_data_cell:
                swap1 dup2 0x20 add mload swap1 sub swap1 // todo: optimize>
                dup6
                dup3 mload sub dup3 mstore
                0x40 add dup1
                mload jump
            decrease_data_pointer_many_then_output_data_cell:
                swap1 dup2 0x20 add mload swap1 sub swap1 // todo: optimize>
                dup2 mload dup4 0x01 add swap4 mstore
                0x40 add dup1
                mload jump
            decrease_data_pointer_many_then_load_input:     // pc dp op ip -1
                swap1 dup2 0x20 add                         // pc' dp pc op ip -1
                mload swap1                                 // dp <x> pc op ip -1
                sub swap1                                   // pc dp' op ip -1
                dup4 0x01 add swap4 calldataload dup3 mstore8
                0x40 add dup1
                mload jump
            decrease_data_pointer_many_then_jump_forward:
                swap1 dup2 0x20 add mload swap1 sub swap1 // todo: optimize>
                dup7
                dup3 mload and skip_ddpm_jump_forward jumpi
                0x40 add mload dup1
                mload jump
                skip_ddpm_jump_forward:
                    0x60 add dup1
                    mload jump
            decrease_data_pointer_many_then_jump_backward: // pc dp op ip -1 1-ish ff-ish
                swap1 dup2 0x20 add mload swap1 sub swap1 // todo: optimize>
                dup7
                dup3 mload and skip_ddpm_jump_backward jumpi
                0x60 add dup1
                mload jump
                skip_ddpm_jump_backward:
                    0x40 add mload dup1
                    mload jump

            increase_data_cell_then_increase_data_pointer: // pc dp op ip -1
                dup2 0x01 add swap2 dup1 mload             // x dp pc dp' op ip -1
                dup8 add  // x' dp pc dp' op ip -1
                swap1 mstore
                0x20 add dup1
                mload jump
            increase_data_cell_then_decrease_data_pointer: // pc dp op ip -1
                0x01 dup3 sub swap2             // dp pc dp' op ip -1 1-ish
                dup7  // 1 dp pc dp' op ip -1
                dup2 mload add  // x' dp pc dp' op ip -1
                swap1 mstore
                0x20 add dup1
                mload jump
            increase_data_cell_twice:
                dup2 mload // x pc dp op ip -1
                0x0200000000000000000000000000000000000000000000000000000000000000 add  // x' dp pc dp' op ip -1
                dup3 mstore
                0x20 add dup1
                mload jump
            increase_data_cell_then_load_input: // ?
                dup4 0x01 add swap4 calldataload // x pc dp op ip -1
                0x20 add dup1
                mload jump
            increase_data_cell_then_output_data_cell:
                dup6
                dup3 mload add      // x pc dp op ip -1
                dup1                // x x pc dp op ip -1
                dup5 0x01 add swap5 mstore
                                    // x pc dp op ip -1
                dup3 mstore
                0x20 add dup1
                mload jump
            increase_data_cell_then_jump_forward:
                dup6
                dup3 mload add      // x pc dp op ip -1
                dup8 dup2 and // x? x pc dp op ip -1
                idc_skip_jump_forward jumpi  // x pc dp op ip -1
                    dup3 mstore
                    0x20 add mload dup1
                    mload jump
                idc_skip_jump_forward:
                    dup3 mstore
                    0x40 add dup1
                    mload jump
            increase_data_cell_then_jump_backward: // pc dp op ip -1 1-ish ff-ish 2-ish
                dup6
                dup3 mload add      // x pc dp op ip -1
                dup8 dup2 and
                idc_jump_backward jumpi
                    dup3 mstore
                    0x40 add dup1
                    mload jump
                idc_jump_backward:
                    dup3 mstore
                    0x20 add mload dup1
                    mload jump


            decrease_data_cell_then_increase_data_pointer: // pc dp op ip -1 1-ish ff-ish 2-ish
                dup2 0x01 add swap2 dup7 dup2 mload             // x dp pc dp' op ip -1
                sub  // x' dp pc dp' op ip -1
                swap1 mstore
                0x20 add dup1
                mload jump
            decrease_data_cell_then_decrease_data_pointer: // pc dp op ip -1
                dup2 dup6 add swap2             // dp pc dp' op ip -1 1-ish ff-ish 2-ish
                dup7  // 1 dp pc dp' op ip -1
                dup2 mload sub  // x' dp pc dp' op ip -1
                swap1 mstore
                0x20 add dup1
                mload jump
            decrease_data_cell_twice:   // pc dp op ip -1 1-ish ff-ish 2-ish
                dup8
                dup3 mload sub
                dup3 mstore
                0x20 add dup1
                mload jump
            decrease_data_cell_then_load_input: // ?
                dup4 0x01 add swap4 calldataload // x pc dp op ip -1
                0x20 add dup1
                mload jump
            decrease_data_cell_then_output_data_cell:  // pc dp op ip -1 1-ish ff-ish 2-ish
                dup6
                dup3 mload sub      // x pc dp op ip -1
                dup1                // x x pc dp op ip -1
                dup5 0x01 add swap5 mstore
                                    // x pc dp op ip -1
                dup3 mstore
                0x20 add dup1
                mload jump
            decrease_data_cell_then_jump_forward:
                dup6
                dup3 mload sub      // x pc dp op ip -1
                dup8 dup2 and // x? x pc dp op ip -1
                ddc_skip_jump_forward jumpi  // x pc dp op ip -1
                    dup3 mstore
                    0x20 add mload dup1
                    mload jump
                ddc_skip_jump_forward:
                    dup3 mstore
                    0x40 add dup1
                    mload jump
            decrease_data_cell_then_jump_backward:   // pc dp op ip -1 1-ish ff-ish
                dup6
                dup3 mload sub      // x pc dp op ip -1 1-ish ff-ish
                dup8 dup2 and
                ddc_jump_backward jumpi
                    dup3 mstore
                    0x40 add dup1
                    mload jump
                ddc_jump_backward:
                    dup3 mstore
                    0x20 add mload dup1
                    mload jump

            output_data_cell_then_increase_data_pointer:
                dup2 0x01 add swap2 mload             // x pc dp' op ip -1
                dup4 0x01 add swap4 mstore
                0x20 add dup1
                mload jump
            output_data_cell_then_decrease_data_pointer:
                dup2 dup6 add swap2 mload             // x pc dp' op ip -1
                dup4 0x01 add swap4 mstore
                0x20 add dup1
                mload jump
            output_data_cell_then_increase_data_cell:
                dup2 mload dup4 0x01 add swap4      // op x pc dp op' ip -1 1-ish ff-ish
                dup2 dup9 add // x' op x pc dp op' ip -1
                dup5 mstore // op x pc dp op' ip -1
                mstore
                // dup3 mload add
                0x20 add dup1
                mload jump

            output_data_cell_then_decrease_data_cell:    
                dup2 mload dup4 0x01 add swap4      // op x pc dp op' ip -1 1-ish ff-ish
                dup8 dup3 sub // x' op x pc dp op' ip -1
                dup5 mstore // op x pc dp op' ip -1
                mstore
                // dup3 mload add
                0x20 add dup1
                mload jump

            output_data_cell_twice:
                dup2 mload dup4 0x02 add swap4    // op x pc dp op' ip -1
                dup2 dup2                       // op' x op x pc dp op' ip -1
                mstore 0x01 add mstore
                0x20 add dup1
                mload jump

            output_data_cell_then_load_input:
                dup2 mload dup4 0x01 add swap4 mstore
                dup4 0x01 add swap4 calldataload dup3 mstore8
                0x20 add dup1
                mload jump
            output_data_cell_then_jump_forward:
                dup2 mload dup1 dup5 0x01 add swap5 mstore     // x pc dp op' ip -1 1-ish ff-ish
                dup8 and // x? pc dp op ip -1
                odc_skip_jump_forward jumpi  // x pc dp op ip -1
                    0x20 add mload dup1
                    mload jump
                odc_skip_jump_forward:
                    0x40 add dup1
                    mload jump
    
            output_data_cell_then_jump_backward:  // pc dp op ip -1 1-ish ff-ish
                dup2 mload dup1 dup5 0x01 add swap5 mstore      // x pc dp op' ip -1 1-ish ff-ish
                dup8 and
                odc_jump_backward jumpi
                    0x40 add dup1
                    mload jump
                odc_jump_backward:
                    0x20 add mload dup1
                    mload jump
            output_data_cell_then_finish_execution:
                dup2 mload dup4 0x01 add swap4 mstore   // op x pc dp op' ip -1
                finish_execution jump

            load_input_then_increase_data_pointer:
                dup4 0x01 add swap4 calldataload dup3 0x01 add swap3 mstore8
                0x20 add dup1
                mload jump

            load_input_then_decrease_data_pointer:
                dup4 0x01 add swap4 calldataload 0x01 dup4 sub swap3 mstore8
                0x20 add dup1
                mload jump

            load_input_then_increase_data_cell:
                dup4 0x01 add swap4 calldataload 0x01 add dup3 mstore8
                0x20 add dup1
                mload jump

            load_input_then_decrease_data_cell:
                0x01 dup5 0x01 add swap5 calldataload sub dup3 mstore8
                0x20 add dup1
                mload jump

            load_input_twice:           // pc dp op ip -1
                swap3 0x02 add swap3 dup4 calldataload dup3 mstore8
                0x20 add dup1
                mload jump

            load_input_then_output_data_cell:
                dup4 0x01 add swap4 calldataload dup3 mstore8
                dup2 mload dup4 0x01 add swap4 mstore
                0x20 add dup1
                mload jump

            load_input_then_jump_forward:
                dup4 0x01 add swap4 calldataload // x pc dp op ip -1
                dup1 0xff and li_skip_jump_forward jumpi
                dup3 mstore8
                0x20 add mload dup1
                mload jump
                li_skip_jump_forward:
                    dup3 mstore8
                    0x40 add dup1
                    mload jump

            load_input_then_jump_backward:
                dup4 0x01 add swap4 calldataload // x pc dp op ip -1
                dup1 0xff and li_jump_backward jumpi
                    dup3 mstore8
                    0x40 add dup1
                    mload jump
                li_jump_backward:
                    dup3 mstore8
                    0x20 add mload dup1
                    mload jump
                
            jump_forward:  // pc dp op ip -1 1-ish ff-ish
                dup7
                dup3 mload and skip_jump_forward jumpi
                0x20 add mload dup1
                mload jump
            skip_jump_forward:
                0x40 add dup1
                mload jump

            jump_backward:  // pc dp op ip -1 1-ish ff-ish
                dup7
                dup3 mload and skip_jump_backward jumpi
                0x40 add dup1
                mload jump
            skip_jump_backward:
                0x20 add mload dup1
                mload jump

                finish_execution:
                0x00 dup4 mstore
                0x400 dup4 sub 0x3e0 mstore
                mstore(0x3c0, 0x20)
                0x60 0x20 0x20 0x401 dup7 sub div mul add 0x3c0 return // there's probably a more efficient way of calculating
                // this, but that would probably require some knowledge of the stack state at this point. Hah.
        // "this just looks like a load of gibberish!" - Joe
        // pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop
        }
    }
}