{$MODE OBJFPC}
type
  proc1 = procedure(var x: array of integer);
  proc2 = procedure(var x, y: integer);
  generic swtable<T> = array[boolean] of T;
  generic P<T> = class(TObject) public class function switch(x: array of T): specialize swtable<T>; static; end;
  P1 = specialize P<proc1>;
  P2 = specialize P<proc2>;

class function P.switch(x: array of T): specialize swtable<T>; begin switch := x end;

procedure nop2(var x, y: integer); begin end;
procedure swap(var x, y: integer); begin x := x xor y; y:= y xor x; x := x xor y end;

procedure nop1(var arr: array of integer); begin end;

procedure inner_sort(var arr: array of integer);
  begin
    P2.switch([@nop2, @swap])[arr[0] > arr[1]](arr[0], arr[1]);
    P1.switch([@nop1, @inner_sort])[length(arr) > 2](arr[1 .. High(arr)])
  end;

procedure sort(var arr: array of integer);
  begin
    P1.switch([@inner_sort, @nop1])[length(arr) < 1](arr);
    P1.switch([@nop1, @sort])[length(arr) > 2](arr[0 .. High(arr) - 1])
  end;

procedure print_array(arr: array of integer);
  var
    i: integer;
  begin
    for i := Low(arr) to High(arr) do Write(arr[i], ' ');
    Writeln
  end;

var
  x : array[-2 .. 2] of integer = (100500, 265, 1488, 666, 13);
begin
  sort(x);
  print_array(x)
end.