Why isn't this shit working?

int * merge(int * a, int as, int * b, int bs) {

if(!a) return b; if(!b) return a;

int * r = malloc((as + bs) * sizeof(int));

int ac = 0, bc = 0, rc = 0;

while(1) {

if (ac == as && bc == bs) break;

else if (ac == as) r[rc++] = b[bc++];

else if (bc == bs) r[rc++] = a[ac++];

else r[rc++] = a[ac] <= b[bc] ? a[ac++] : b[bc++];

}

free(a); free(b);

return r;

}

int * msort(int * k, int s) {

if (s == 0) return NULL;

if (s == 1) return k;

int s1 = s/2, s2 = (s/2) + (s%2) ? 1 : 0;

return merge(msort(memcpy(malloc(s1*sizeof(int)), k, s1), s1), s1,

msort(memcpy(malloc(s2*sizeof(int)), k+s1, s2), s2), s2);

}