1// RUN: %clangxx -O2 %s -o %t
2
3#include <algorithm>
4#include <assert.h>
5#include <stdio.h>
6#include <stdlib.h>
7#include <vector>
8
9static int compare_ints(const void *a, const void *b) {
10 return *(const int *)b - *(const int *)a;
11}
12
13int main() {
14 std::vector<int> nums(100000);
15 for (auto &n : nums)
16 n = rand();
17
18 std::vector<int> to_qsort = nums;
19 qsort(base: to_qsort.data(), nmemb: to_qsort.size(), size: sizeof(to_qsort[0]), compar: &compare_ints);
20
21 std::sort(first: nums.begin(), last: nums.end());
22
23 assert(nums == to_qsort);
24}
25

source code of compiler-rt/test/sanitizer_common/TestCases/Posix/qsort.cpp