#include <stdlib.h>
#include <stdio.h>
#include <string.h>

void __attribute__ ((noinline,noipa)) stwlf(long *ns, long *wl, long *ws, long *nl, size_t n)
{
  size_t i;
  for (i=0; i<n; i+=4) {
    long wl0, wl1;
    ns[i] = nl[i]+1;
    wl0 = wl[i];
    wl1 = wl[i+1];
    ws[i] = wl0;
    ws[i+1] = wl1;
  }
}

long min(long a, long b)
{
  if (a<b)
    return a;
  else
    return b;
}

long max(long a, long b)
{
  if (a>b)
    return a;
  else
    return b;
}

#define ITER 1000

int main(int argc, char **argv)
{
  if (argc != 5) {
    fprintf(stderr,"usage: %s ns-index wl-index ws-index nl-index\n",argv[0]);
    return 1;
  }
  long ai = strtol(argv[1],NULL,10);
  long bi = strtol(argv[2],NULL,10);
  long ci = strtol(argv[3],NULL,10);
  long di = strtol(argv[4],NULL,10);
  long mini = min(ai,min(bi,min(ci,di)));
  long maxi = max(ai,max(bi+1,max(ci+1,di)));
  size_t size = (ITER*4-mini+maxi+1)*sizeof(long);
  long *m1 = (long *)malloc(size);
  long *m = m1-mini;
  size_t i;
  memset(m1,0,size);
  for (i=0; i<100000; i++)
    stwlf(m+ai,m+bi,m+ci,m+di,ITER*4);
  return 0;
}
