void test_ulong_range(unsigned long n) {
  const unsigned long max = (0x7fffffffffffffffL * 2LU + 1);
  sink(f_ulong_1(n));
  sink(f_ulong_1(unsigned_range(0, 1)));
  sink(f_ulong_1(unsigned_range(0, max - 1)));
  sink(f_ulong_1(unsigned_range(1, max - 1)));
  sink(f_ulong_1(unsigned_range(1, max)));
}


x86 assembly (clang, -O0):
<test_ulong_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0xffffffffffffffff,-0x10(%rbp)
ff
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1030 <f_ulong_1@plt>
mov    %eax,%edi
mov    $0x0,%al
call   1040 <sink@plt>
xor    %edi,%edi
mov    $0x1,%esi
mov    $0x0,%al
call   1050 <unsigned_range@plt>
mov    %eax,%edi
mov    $0x0,%al
call   1030 <f_ulong_1@plt>
mov    %eax,%edi
mov    $0x0,%al
call   1040 <sink@plt>
xor    %edi,%edi
mov    $0xfffffffffffffffe,%rsi
mov    $0x0,%al
call   1050 <unsigned_range@plt>
mov    %eax,%edi
mov    $0x0,%al
call   1030 <f_ulong_1@plt>
mov    %eax,%edi
mov    $0x0,%al
call   1040 <sink@plt>
mov    $0x1,%edi
mov    $0xfffffffffffffffe,%rsi
mov    $0x0,%al
call   1050 <unsigned_range@plt>
mov    %eax,%edi
mov    $0x0,%al
call   1030 <f_ulong_1@plt>
mov    %eax,%edi
mov    $0x0,%al
call   1040 <sink@plt>
mov    $0x1,%edi
mov    $0xffffffffffffffff,%rsi
mov    $0x0,%al
call   1050 <unsigned_range@plt>
mov    %eax,%edi
mov    $0x0,%al
call   1030 <f_ulong_1@plt>
mov    %eax,%edi
mov    $0x0,%al
call   1040 <sink@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_ulong_range>:
push   %rax
xor    %eax,%eax
call   1030 <f_ulong_1@plt>
mov    %eax,%edi
xor    %eax,%eax
call   1040 <sink@plt>
xor    %edi,%edi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <unsigned_range@plt>
mov    %eax,%edi
xor    %eax,%eax
call   1030 <f_ulong_1@plt>
mov    %eax,%edi
xor    %eax,%eax
call   1040 <sink@plt>
xor    %edi,%edi
mov    $0xfffffffffffffffe,%rsi
xor    %eax,%eax
call   1050 <unsigned_range@plt>
mov    %eax,%edi
xor    %eax,%eax
call   1030 <f_ulong_1@plt>
mov    %eax,%edi
xor    %eax,%eax
call   1040 <sink@plt>
mov    $0x1,%edi
mov    $0xfffffffffffffffe,%rsi
xor    %eax,%eax
call   1050 <unsigned_range@plt>
mov    %eax,%edi
xor    %eax,%eax
call   1030 <f_ulong_1@plt>
mov    %eax,%edi
xor    %eax,%eax
call   1040 <sink@plt>
mov    $0x1,%edi
mov    $0xffffffffffffffff,%rsi
xor    %eax,%eax
call   1050 <unsigned_range@plt>
mov    %eax,%edi
xor    %eax,%eax
call   1030 <f_ulong_1@plt>
mov    %eax,%edi
xor    %eax,%eax
pop    %rcx
jmp    1040 <sink@plt>

LLVM IR (-O0):
define void @test_ulong_range(i64 %0) {
%2 = alloca i64
%3 = alloca i64
store i64 %0, i64* %2
store i64 -1, i64* %3
%4 = load i64, i64* %2
%5 = call i32 (i64, ...) bitcast (i32 (...)* @f_ulong_1 to i32 (i64, ...)*)(i64 %4)
%6 = call i32 (i32, ...) bitcast (i32 (...)* @sink to i32 (i32, ...)*)(i32 %5)
%7 = call i32 (i32, i32, ...) bitcast (i32 (...)* @unsigned_range to i32 (i32, i32, ...)*)(i32 0, i32 1)
%8 = call i32 (i32, ...) bitcast (i32 (...)* @f_ulong_1 to i32 (i32, ...)*)(i32 %7)
%9 = call i32 (i32, ...) bitcast (i32 (...)* @sink to i32 (i32, ...)*)(i32 %8)
%10 = call i32 (i32, i64, ...) bitcast (i32 (...)* @unsigned_range to i32 (i32, i64, ...)*)(i32 0, i64 -2)
%11 = call i32 (i32, ...) bitcast (i32 (...)* @f_ulong_1 to i32 (i32, ...)*)(i32 %10)
%12 = call i32 (i32, ...) bitcast (i32 (...)* @sink to i32 (i32, ...)*)(i32 %11)
%13 = call i32 (i32, i64, ...) bitcast (i32 (...)* @unsigned_range to i32 (i32, i64, ...)*)(i32 1, i64 -2)
%14 = call i32 (i32, ...) bitcast (i32 (...)* @f_ulong_1 to i32 (i32, ...)*)(i32 %13)
%15 = call i32 (i32, ...) bitcast (i32 (...)* @sink to i32 (i32, ...)*)(i32 %14)
%16 = call i32 (i32, i64, ...) bitcast (i32 (...)* @unsigned_range to i32 (i32, i64, ...)*)(i32 1, i64 -1)
%17 = call i32 (i32, ...) bitcast (i32 (...)* @f_ulong_1 to i32 (i32, ...)*)(i32 %16)
%18 = call i32 (i32, ...) bitcast (i32 (...)* @sink to i32 (i32, ...)*)(i32 %17)
ret void
}

LLVM IR (-O2):
define void @test_ulong_range(i64 %0) {
%2 = tail call i32 (i64, ...) bitcast (i32 (...)* @f_ulong_1 to i32 (i64, ...)*)(i64 %0)
%3 = tail call i32 (i32, ...) bitcast (i32 (...)* @sink to i32 (i32, ...)*)(i32 %2)
%4 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @unsigned_range to i32 (i32, i32, ...)*)(i32 0, i32 1)
%5 = tail call i32 (i32, ...) bitcast (i32 (...)* @f_ulong_1 to i32 (i32, ...)*)(i32 %4)
%6 = tail call i32 (i32, ...) bitcast (i32 (...)* @sink to i32 (i32, ...)*)(i32 %5)
%7 = tail call i32 (i32, i64, ...) bitcast (i32 (...)* @unsigned_range to i32 (i32, i64, ...)*)(i32 0, i64 -2)
%8 = tail call i32 (i32, ...) bitcast (i32 (...)* @f_ulong_1 to i32 (i32, ...)*)(i32 %7)
%9 = tail call i32 (i32, ...) bitcast (i32 (...)* @sink to i32 (i32, ...)*)(i32 %8)
%10 = tail call i32 (i32, i64, ...) bitcast (i32 (...)* @unsigned_range to i32 (i32, i64, ...)*)(i32 1, i64 -2)
%11 = tail call i32 (i32, ...) bitcast (i32 (...)* @f_ulong_1 to i32 (i32, ...)*)(i32 %10)
%12 = tail call i32 (i32, ...) bitcast (i32 (...)* @sink to i32 (i32, ...)*)(i32 %11)
%13 = tail call i32 (i32, i64, ...) bitcast (i32 (...)* @unsigned_range to i32 (i32, i64, ...)*)(i32 1, i64 -1)
%14 = tail call i32 (i32, ...) bitcast (i32 (...)* @f_ulong_1 to i32 (i32, ...)*)(i32 %13)
%15 = tail call i32 (i32, ...) bitcast (i32 (...)* @sink to i32 (i32, ...)*)(i32 %14)
ret void
}