1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_divdi3
3 
4 #include "int_lib.h"
5 #include <stdio.h>
6 
7 // Returns: a / b
8 
9 COMPILER_RT_ABI di_int __divdi3(di_int a, di_int b);
10 
test__divdi3(di_int a,di_int b,di_int expected)11 int test__divdi3(di_int a, di_int b, di_int expected)
12 {
13     di_int x = __divdi3(a, b);
14     if (x != expected)
15         printf("error in __divdi3: %lld / %lld = %lld, expected %lld\n",
16                a, b, x, expected);
17     return x != expected;
18 }
19 
20 char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
21 
main()22 int main()
23 {
24     if (test__divdi3(0, 1, 0))
25         return 1;
26     if (test__divdi3(0, -1, 0))
27         return 1;
28 
29     if (test__divdi3(2, 1, 2))
30         return 1;
31     if (test__divdi3(2, -1, -2))
32         return 1;
33     if (test__divdi3(-2, 1, -2))
34         return 1;
35     if (test__divdi3(-2, -1, 2))
36         return 1;
37 
38     if (test__divdi3(0x8000000000000000LL, 1, 0x8000000000000000LL))
39         return 1;
40     if (test__divdi3(0x8000000000000000LL, -1, 0x8000000000000000LL))
41         return 1;
42     if (test__divdi3(0x8000000000000000LL, -2, 0x4000000000000000LL))
43         return 1;
44     if (test__divdi3(0x8000000000000000LL, 2, 0xC000000000000000LL))
45         return 1;
46 
47     return 0;
48 }
49