2 // RUN: %clangxx -O0 %s -o %t && %run %t 2>&1 | FileCheck %s
4 // Inlined bsearch works even without interceptors.
5 // RUN: %clangxx -O2 %s -o %t && %run %t 2>&1 | FileCheck %s
10 static int arr1
[] = {8, 7, 6, 5, 4, 3, 2, 1, 0};
11 static int arr2
[] = {10, 1, 1, 3, 4, 6, 7, 7};
13 #define array_size(x) (sizeof(x) / sizeof(x[0]))
15 static int cmp_ints(const void *a
, const void *b
) {
16 return *(const int *)b
- *(const int *)a
;
19 static int cmp_pos(const void *a
, const void *b
) {
21 (const int *)bsearch(a
, arr1
, array_size(arr1
), sizeof(int), &cmp_ints
);
23 ap
= arr1
+ array_size(arr1
);
25 (const int *)bsearch(b
, arr1
, array_size(arr1
), sizeof(int), &cmp_ints
);
27 bp
= arr1
+ array_size(arr1
);
33 for (int i
= 0; i
< 10; ++i
) {
35 bsearch(&i
, arr1
, array_size(arr1
), sizeof(arr1
[0]), &cmp_ints
);
39 printf(" %d", *(const int *)r
);
42 // CHECK: 0 1 2 3 4 5 6 7 8 null
45 for (int i
= 0; i
< 10; ++i
) {
47 bsearch(&i
, arr2
, array_size(arr2
), sizeof(arr2
[0]), &cmp_pos
);
51 printf(" %d", *(const int *)r
);
54 // CHECK: null 1 null 3 4 null 6 7 null 10