     ] [
         rep load-return-value
     ] if
-    rep int-rep? [ func %vm-invoke-2nd-arg ] [ func %vm-invoke-1st-arg ] if ;
+    rep int-rep? [ param-reg-2 ] [ param-reg-1 ] if %mov-vm-ptr
+    func f %alien-invoke ;
 
 M: x86.64 %box-long-long ( n func -- )
     [ int-rep ] dip %box ;

    param-reg-1 R14 [] MOV
    R14 cell SUB ;

: %vm-invoke-1st-arg ( function -- )
    param-reg-1 0 MOV rc-absolute-cell rt-vm rel-fixup
    f %alien-invoke ;

: %vm-invoke-2nd-arg ( function -- )
    param-reg-2 0 MOV rc-absolute-cell rt-vm rel-fixup
    f %alien-invoke ;

: %vm-invoke-3rd-arg ( function -- )
    param-reg-3 0 MOV rc-absolute-cell rt-vm rel-fixup
    f %alien-invoke ;

: %vm-invoke-4th-arg ( function -- )
    int-regs param-regs fourth 0 MOV rc-absolute-cell rt-vm rel-fixup
    f %alien-invoke ;


M:: x86.64 %unbox ( n rep func -- )
    ! Call the unboxer
    func %vm-invoke-2nd-arg
    ! Store the return value on the C stack if this is an
    ! alien-invoke, otherwise leave it the return register if
    ! this is the end of alien-callback

: param-reg-1 ( -- reg ) int-regs param-regs first ; inline
: param-reg-2 ( -- reg ) int-regs param-regs second ; inline
: param-reg-3 ( -- reg ) int-regs param-regs third ; inline
: param-reg-4 ( -- reg ) int-regs param-regs fourth ; inline

M: x86.64 pic-tail-reg RBX ;

