Objective
Write qsort with the signature the C standard gives it: order the nmemb elements of size bytes stored at base, comparing any two of them with cmp, and move whole elements byte by byte because size is only known at run time.
Steps
$ int v[] = {4, 1, 7, 3}; qsort(v, 4, sizeof(int), cmp_int_asc);
1 3 4 7
$ struct rec v[] = {{30, 3, 300}, {10, 1, 100}, {20, 2, 200}}; qsort(v, 3, sizeof(struct rec), cmp_rec_key); // printed as key:serial:weight
10:1:100 20:2:200 30:3:300
$ char v[][3] = {"zz", "ab", "mm"}; qsort(v, 3, 3, cmp_tag_head);
ab mm zz
$ char v[] = {'g', 'a', 'z', 'm'}; qsort(v, 4, sizeof(char), cmp_char_asc); // printed with no separator
agmz
$ struct rec v[] = {{5, 1, 0}, {5, 2, 0}, {5, 3, 0}}; qsort(v, 3, sizeof(struct rec), cmp_rec_key); // keys, then the serial total
5 5 5 sum=6
$ int v[3] = {9, 8, 7}; qsort(v, 0, sizeof(int), cmp_int_asc);
9 8 7
Expected files
Allowed functions
None. Write every helper yourself.
Allowed headers
Standard C library
Implements the contract of a function from the standard C library.

Objective
Write qsort with the signature the C standard gives it: order the nmemb elements of size bytes stored at base, comparing any two of them with cmp, and move whole elements byte by byte because size is only known at run time.
Steps
$ int v[] = {4, 1, 7, 3}; qsort(v, 4, sizeof(int), cmp_int_asc);
1 3 4 7
$ struct rec v[] = {{30, 3, 300}, {10, 1, 100}, {20, 2, 200}}; qsort(v, 3, sizeof(struct rec), cmp_rec_key); // printed as key:serial:weight
10:1:100 20:2:200 30:3:300
$ char v[][3] = {"zz", "ab", "mm"}; qsort(v, 3, 3, cmp_tag_head);
ab mm zz
$ char v[] = {'g', 'a', 'z', 'm'}; qsort(v, 4, sizeof(char), cmp_char_asc); // printed with no separator
agmz
$ struct rec v[] = {{5, 1, 0}, {5, 2, 0}, {5, 3, 0}}; qsort(v, 3, sizeof(struct rec), cmp_rec_key); // keys, then the serial total
5 5 5 sum=6
$ int v[3] = {9, 8, 7}; qsort(v, 0, sizeof(int), cmp_int_asc);
9 8 7
Expected files
Allowed functions
None. Write every helper yourself.
Allowed headers
Standard C library
Implements the contract of a function from the standard C library.

Tests
Run the tests to grade your code