// automatically generated from `@stdlib/std/stdlib.fc` `/home/alex/Dokumente/dzk-ton/contracts/contracts/output/test/test-simple.tact_TestSimple.fc` 
PROGRAM{
  DECLPROC $TestSimple$_store
  DECLPROC $TestSimple$_load
  DECLPROC $TestSimple$_contract_init
  DECLPROC $TestSimple$_contract_load
  DECLPROC $TestSimple$_contract_store
  DECLPROC $TestSimple$_fun_counter
  104984 DECLMETHOD %counter
  DECLPROC recv_internal
  65535 DECLMETHOD __tact_selector_hack
  DECLGLOBVAR __tact_context
  DECLGLOBVAR __tact_context_sender
  DECLGLOBVAR __tact_child_contract_codes
  DECLGLOBVAR __tact_randomized
  $TestSimple$_store PROCINLINE:<{
    SWAP
    32 STU
  }>
  $TestSimple$_load PROCINLINE:<{
    32 LDU
    SWAP
  }>
  $TestSimple$_contract_init PROCINLINE:<{
    0 PUSHINT
  }>
  $TestSimple$_contract_load PROCINLINE:<{
    c4 PUSH
    CTOS
    1 LDI
    SWAP
    IF:<{
      $TestSimple$_load INLINECALLDICT
      NIP
    }>ELSE<{
      DROP
      $TestSimple$_contract_init INLINECALLDICT
    }>
  }>
  $TestSimple$_contract_store PROCINLINE:<{
    NEWC
    TRUE
    SWAP
    1 STI
    SWAP
    $TestSimple$_store INLINECALLDICT
    ENDC
    c4 POP
  }>
  $TestSimple$_fun_counter PROCREF:<{
    DUP
  }>
  %counter PROC:<{
    $TestSimple$_contract_load INLINECALLDICT
    $TestSimple$_fun_counter INLINECALLDICT
    NIP
  }>
  recv_internal PROC:<{
    SWAP
    CTOS
    2 PUSHINT
    SDSKIPFIRST
    1 LDI
    1 LDI
    LDMSGADDR
    OVER
    s3 s4 XCHG
    s6 s6 XCHG2
    4 TUPLE
    __tact_context SETGLOB
    s0 s2 XCHG
    __tact_context_sender SETGLOB
    $TestSimple$_contract_load INLINECALLDICT
    s0 s2 XCHG
    IFJMP:<{
      2DROP
    }>
    32 LDUQ 130 THROWIFNOT
    SWAP
    1 EQINT
    IFJMP:<{
      32 LDU
      DROP
      ADD
      $TestSimple$_contract_store INLINECALLDICT
    }>
    2DROP
    130 THROW
  }>
  __tact_selector_hack PROC:<{
    @atend @ 1 {
            execute current@ context@ current!
            {
                // The core idea of this function is to save gas by avoiding unnecessary dict jump, when recv_internal/recv_external is called
                // We want to extract recv_internal/recv_external from the dict and select needed function
                // not by jumping to the needed function by it's index, but by using usual IF statements.
                }END> b> // Close previous builder, now we have a cell of previous code on top of the stack
                <{ // Start of the new code builder
                    SETCP0
                    // Swap the new code builder with the previous code, now we have previous code on top of the stack
                    swap
                    // Transform cell to slice and load first ref from the previous code, now we have the dict on top of the stack
                    <s ref@
                    // Extract the recv_internal from the dict
                    dup 0 swap @procdictkeylen idict@ { "internal shortcut error" abort } ifnot
                    swap
                    // Delete the recv_internal from the dict
                    0 swap @procdictkeylen idict- drop
                    // Delete the recv_external from the dict (it's okay if it's not there)
                    -1 swap @procdictkeylen idict- drop
                    // Delete the __tact_selector_hack from the dict
                    65535 swap @procdictkeylen idict- drop
                    // Bring the code builder from the bottom of the stack
                    // because if recv_external extraction is optional, and the number of elements on the stack is not fixed
                    depth 1- roll
                    // Swap with the dict from which we extracted recv_internal and (maybe) recv_external
                    swap
                    // Check if the dict is empty
                    dup null?
                    // Store a copy of this flag in the bottom of the stack
                    dup depth 1- -roll
                    {
                        // If the dict is empty, just drop it (it will be null if it's empty)
                        drop
                    }
                    {
                        // If the dict is not empty, prepare continuation to be stored in c3
                        <{
                            // Save this dict as first ref in this continuation, it will be pushed in runtime by DICTPUSHCONST
                            swap @procdictkeylen DICTPUSHCONST
                            // Jump to the needed function by it's index
                            DICTIGETJMPZ
                            // If such key is not found, throw 11 along with the key as an argument
                            11 THROWARG
                        }> PUSHCONT
                        // Store the continuation in c3
                        c3 POP
                    } cond
                    // Function id is on top of the (runtime) stack
                    DUP IFNOTJMP:<{
                        // place recv_internal here
                        DROP swap @addop
                    }>
                    // Bring back the flag, indicating if the dict is empty or not from the bottom of the stack
                    depth 1- roll
                    {
                        // If the dict is empty, throw 11
                        11 THROWARG
                    }
                    {
                        // If the dict is not empty, jump to continuation from c3
                        c3 PUSH JMPX
                    } cond
                }> b>
            } : }END>c
            current@ context! current!
        } does @atend !
  }>
}END>c
