%#codegen
% Cast fi arguments to int and call given function
function [A, B, C, D, E] = f2f_call_with_fi_toint(fcn, argIdx, varargin)
    coder.inline('always');
    if argIdx > numel(varargin)
        switch nargout
            case 1, A = fcn(varargin{:});
            case 2, [A, B] = fcn(varargin{:});
            case 3, [A, B, C] = fcn(varargin{:});
            case 4, [A, B, C, D] = fcn(varargin{:});
            case 5, [A, B, C, D, E] = fcn(varargin{:});
        end
    else
        switch nargout
            case 1, A = f2f_call_with_fi_toint_impl(fcn, argIdx+1, varargin{1:argIdx-1}, fi_toint(varargin{argIdx}), varargin{argIdx+1:end});
            case 2, [A, B] = f2f_call_with_fi_toint_impl(fcn, argIdx+1, varargin{1:argIdx-1}, fi_toint(varargin{argIdx}), varargin{argIdx+1:end});
            case 3, [A, B, C] = f2f_call_with_fi_toint_impl(fcn, argIdx+1, varargin{1:argIdx-1}, fi_toint(varargin{argIdx}), varargin{argIdx+1:end});
            case 4, [A, B, C, D] = f2f_call_with_fi_toint_impl(fcn, argIdx+1, varargin{1:argIdx-1}, fi_toint(varargin{argIdx}), varargin{argIdx+1:end});
            case 5, [A, B, C, D, E] = f2f_call_with_fi_toint_impl(fcn, argIdx+1, varargin{1:argIdx-1}, fi_toint(varargin{argIdx}), varargin{argIdx+1:end});
        end
    end
end

function [A, B, C, D, E] = f2f_call_with_fi_toint_impl(fcn, argIdx, varargin)
    % Indirect recursion
    coder.inline('always');
    if argIdx > numel(varargin)
        switch nargout
            case 1, A = fcn(varargin{:});
            case 2, [A, B] = fcn(varargin{:});
            case 3, [A, B, C] = fcn(varargin{:});
            case 4, [A, B, C, D] = fcn(varargin{:});
            case 5, [A, B, C, D, E] = fcn(varargin{:});
        end
    else
        switch nargout
            case 1, A = f2f_call_with_fi_toint(fcn, argIdx+1, varargin{1:argIdx-1}, fi_toint(varargin{argIdx}), varargin{argIdx+1:end});
            case 2, [A, B] = f2f_call_with_fi_toint(fcn, argIdx+1, varargin{1:argIdx-1}, fi_toint(varargin{argIdx}), varargin{argIdx+1:end});
            case 3, [A, B, C] = f2f_call_with_fi_toint(fcn, argIdx+1, varargin{1:argIdx-1}, fi_toint(varargin{argIdx}), varargin{argIdx+1:end});
            case 4, [A, B, C, D] = f2f_call_with_fi_toint(fcn, argIdx+1, varargin{1:argIdx-1}, fi_toint(varargin{argIdx}), varargin{argIdx+1:end});
            case 5, [A, B, C, D, E] = f2f_call_with_fi_toint(fcn, argIdx+1, varargin{1:argIdx-1}, fi_toint(varargin{argIdx}), varargin{argIdx+1:end});
        end
    end
end
