[
subtracts one from a word using only the input word and one addi
]

decrement_word{
    = `A0 A1 A2 A3 | p0 p1 | 0 0 0 0
    >>>>>>
    copy A3
    <<<[>>>+>+<<<<-]>>>
    = A0 A1 A2 0 | p0 p1 | `A3 A3 0 0
    -
    = A0 A1 A2 0 | p0 p1 | `A3_dec A3 0 0
    [<<<+>>>-]
    = A0 A1 A2 A3_dec | p0 p1 | `0 A3 0 0
    check_if_zero{
        +>
        = A0 A1 A2 A3_dec | p0 p1 | 1 `A3 0 0
        if A3 is 1 clear the cell to the left
        [
            <[-]
            >[-]
        ]<
        = A0 A1 A2 A3_dec | p0 p1 | `A3_was_zero 0 0 0
    }
    [
        A3 was zero
        [-]
        = A0 A1 A2 A3 | p0 p1 | `0 0 0 0
        copy A2
        <<<<[>>>>+>+<<<<<-]>>>>
        = A0 A1 0 A3_dec | p0 p1 | `A2 A2 0 0
        -
        = A0 A1 0 A3_dec | p0 p1 | `A2_dec A2 0 0
        [<<<<+>>>>-]
        = A0 A1 A2_dec A3_dec | p0 p1 | `0 A2 0 0
        check_if_zero{ +>[<[-]>[-]]< }
        = A0 A1 A2_dec A3_dec | p0 p1 | `A2_was_zero 0 0 0
        [
            A2 was zero
            [-]
            = A0 A1 A2 A3 | p0 p1 | `0 0 0 0
            copy A1
            <<<<<[>>>>>+>+<<<<<<-]>>>>>
            = A0 0 A2_dec A3_dec | p0 p1 | `A1 A1 0 0
            -
            = A0 0 A2_dec A3_dec | p0 p1 | `A1_dec A1 0 0
            [<<<<<+>>>>>-]
            = A0 A1_dec A2_dec A3_dec | p0 p1 | `0 A1 0 0
            check_if_zero{ +>[<[-]>[-]]< }
            = A0 A1_dec A2_dec A3_dec | p0 p1 | `A1_was_zero 0 0 0
            [
                TODO: complete this final section
                A1 was zero
                [-]
                = A0 A1 A2 A3 | p0 p1 | `0 0 0 0
                copy A0
                <<<<<<[>>>>>>+>+<<<<<<<-]>>>>>>
                = 0 A1_dec A2_dec A3_dec | p0 p1 | `A0 A0 0 0
                -
                = 0 A1_dec A2_dec A3_dec | p0 p1 | `A0_dec A0 0 0
                [<<<<<<+>>>>>>-]
                = A0_dec A1_dec A2_dec A3_dec | p0 p1 | `0 A0 0 0
                check_if_zero{ +>[<[-]>[-]]< }
                = A0_dec A1_dec A2_dec A3_dec | p0 p1 | `A0_was_zero 0 0 0
                [>+<-]
                = A0_dec A1_dec A2_dec A3_dec | p0 p1 | `0 A0_was_zero 0 0
            ]
        ]
    ]
    <<<<<<
    = `B0 B1 B2 B3 | p0 p1 | 0 turned_over 0 0
}

= ~

TEST: can decrement 1
>>>+<<<
= `0 0 0 1 | 0 0 | 0 0 0 0 | 0 0 | 0 0 0 0
decrement_word{
    >>>>>><<<[>>>+>+<<<<-]>>>-[<<<+>>>-]+>[<[-]>[-]]<[[-]<<<<[>>>>+>+<<<<<-]>>>>-[<<
    <<+>>>>-]+>[<[-]>[-]]<[[-]<<<<<[>>>>>+>+<<<<<<-]>>>>>-[<<<<<+>>>>>-]+>[<[-]>[-]]
    <[[-]<<<<<<[>>>>>>+>+<<<<<<<-]>>>>>>-[<<<<<<+>>>>>>-]+>[<[-]>[-]]<[>+<-]]]]<<<<<
    <
}
= `0 0 0 0 | 0 0 | 0 0 0 0 | 0 0 | 0 0 0 0
[-]>[-]>[-]>[-]<<<

TEST: can decrement 3
>>>+++<<<
= `0 0 0 3 | 0 0 | 0 0 0 0 | 0 0 | 0 0 0 0
decrement_word{
    >>>>>><<<[>>>+>+<<<<-]>>>-[<<<+>>>-]+>[<[-]>[-]]<[[-]<<<<[>>>>+>+<<<<<-]>>>>-[<<
    <<+>>>>-]+>[<[-]>[-]]<[[-]<<<<<[>>>>>+>+<<<<<<-]>>>>>-[<<<<<+>>>>>-]+>[<[-]>[-]]
    <[[-]<<<<<<[>>>>>>+>+<<<<<<<-]>>>>>>-[<<<<<<+>>>>>>-]+>[<[-]>[-]]<[>+<-]]]]<<<<<
    <
}
= `0 0 0 2 | 0 0 | 0 0 0 0 | 0 0 | 0 0 0 0
[-]>[-]>[-]>[-]<<<

TEST: can decrement 256
>>+<<
= `0 0 1 0 | 0 0 | 0 0 0 0 | 0 0 | 0 0 0 0
decrement_word{
    >>>>>><<<[>>>+>+<<<<-]>>>-[<<<+>>>-]+>[<[-]>[-]]<[[-]<<<<[>>>>+>+<<<<<-]>>>>-[<<
    <<+>>>>-]+>[<[-]>[-]]<[[-]<<<<<[>>>>>+>+<<<<<<-]>>>>>-[<<<<<+>>>>>-]+>[<[-]>[-]]
    <[[-]<<<<<<[>>>>>>+>+<<<<<<<-]>>>>>>-[<<<<<<+>>>>>>-]+>[<[-]>[-]]<[>+<-]]]]<<<<<
    <
}
= `0 0 0 255 | 0 0 | 0 0 0 0 | 0 0 | 0 0 0 0
[-]>[-]>[-]>[-]<<<

TEST: can decrement 4294967295
->->->-<<<
= `255 255 255 255 | 0 0 | 0 0 0 0 | 0 0 | 0 0 0 0
decrement_word{
    >>>>>><<<[>>>+>+<<<<-]>>>-[<<<+>>>-]+>[<[-]>[-]]<[[-]<<<<[>>>>+>+<<<<<-]>>>>-[<<
    <<+>>>>-]+>[<[-]>[-]]<[[-]<<<<<[>>>>>+>+<<<<<<-]>>>>>-[<<<<<+>>>>>-]+>[<[-]>[-]]
    <[[-]<<<<<<[>>>>>>+>+<<<<<<<-]>>>>>>-[<<<<<<+>>>>>>-]+>[<[-]>[-]]<[>+<-]]]]<<<<<
    <
}
= `255 255 255 254 | 0 0 | 0 0 0 0 | 0 0 | 0 0 0 0
[-]>[-]>[-]>[-]<<<

TEST: can decrement 0
= `0 0 0 0 | 0 0 | 0 0 0 0 | 0 0 | 0 0 0 0
decrement_word{
    >>>>>><<<[>>>+>+<<<<-]>>>-[<<<+>>>-]+>[<[-]>[-]]<[[-]<<<<[>>>>+>+<<<<<-]>>>>-[<<
    <<+>>>>-]+>[<[-]>[-]]<[[-]<<<<<[>>>>>+>+<<<<<<-]>>>>>-[<<<<<+>>>>>-]+>[<[-]>[-]]
    <[[-]<<<<<<[>>>>>>+>+<<<<<<<-]>>>>>>-[<<<<<<+>>>>>>-]+>[<[-]>[-]]<[>+<-]]]]<<<<<
    <
}
= `255 255 255 255 | 0 0 | 0 1 0 0 | 0 0 | 0 0 0 0
[-]>[-]>[-]>[-]<<<
