#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
unsigned long long _pext_u64(unsigned long long, unsigned long long);
int /*<<< orphan*/ abort();
unsigned long long calc_pext_u64(unsigned long long, unsigned long long);
void bmi2_test() {
  unsigned long long i;
  unsigned long long src = 0xce7acce7acce7ac;
  unsigned long long res, res_ref;
  for (i = 0; i < 5; ++i) {
    src = src * (i + 1);
    res_ref = calc_pext_u64(src, ~(i * 3));
    res = _pext_u64(src, ~(i * 3));
    if (res != res_ref)
      abort();
  }
}


x86 assembly (clang, -O0):
<bmi2_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movabs $0xce7acce7acce7ac,%rax
ac e7 0c
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x8(%rbp)
cmpq   $0x5,-0x8(%rbp)
jae    11c4 <bmi2_test+0x94>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
add    $0x1,%rcx
imul   %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
imul   $0x3,-0x8(%rbp),%rsi
xor    $0xffffffffffffffff,%rsi
call   1050 <calc_pext_u64@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
imul   $0x3,-0x8(%rbp),%rsi
xor    $0xffffffffffffffff,%rsi
call   1040 <_pext_u64@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     11ae <bmi2_test+0x7e>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    11b3 <bmi2_test+0x83>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    114e <bmi2_test+0x1e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bmi2_test>:
push   %r14
push   %rbx
push   %rax
movabs $0xce7acce7acce7ac,%r14
ac e7 0c
mov    %r14,%rdi
mov    $0xffffffffffffffff,%rsi
call   1050 <calc_pext_u64@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0xffffffffffffffff,%rsi
call   1040 <_pext_u64@plt>
cmp    %rbx,%rax
jne    1234 <bmi2_test+0x104>
movabs $0x19cf599cf599cf58,%r14
59 cf 19
mov    %r14,%rdi
mov    $0xfffffffffffffffc,%rsi
call   1050 <calc_pext_u64@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0xfffffffffffffffc,%rsi
call   1040 <_pext_u64@plt>
cmp    %rbx,%rax
jne    1234 <bmi2_test+0x104>
movabs $0x4d6e0cd6e0cd6e08,%r14
0c 6e 4d
mov    %r14,%rdi
mov    $0xfffffffffffffff9,%rsi
call   1050 <calc_pext_u64@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0xfffffffffffffff9,%rsi
call   1040 <_pext_u64@plt>
cmp    %rbx,%rax
jne    1234 <bmi2_test+0x104>
movabs $0x35b8335b8335b820,%r14
33 b8 35
mov    %r14,%rdi
mov    $0xfffffffffffffff6,%rsi
call   1050 <calc_pext_u64@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0xfffffffffffffff6,%rsi
call   1040 <_pext_u64@plt>
cmp    %rbx,%rax
jne    1234 <bmi2_test+0x104>
movabs $0xc9900c9900c98a0,%r14
mov    %r14,%rdi
mov    $0xfffffffffffffff3,%rsi
call   1050 <calc_pext_u64@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0xfffffffffffffff3,%rsi
call   1040 <_pext_u64@plt>
cmp    %rbx,%rax
jne    1234 <bmi2_test+0x104>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
define void @bmi2_test() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 929901850898786220, i64* %2
store i64 0, i64* %1
br label %5
5: ; preds = %29, %0
%6 = load i64, i64* %1
%7 = icmp ult i64 %6, 5
br i1 %7, label %8, label %32
8: ; preds = %5
%9 = load i64, i64* %2
%10 = load i64, i64* %1
%11 = add i64 %10, 1
%12 = mul i64 %9, %11
store i64 %12, i64* %2
%13 = load i64, i64* %2
%14 = load i64, i64* %1
%15 = mul i64 %14, 3
%16 = xor i64 %15, -1
%17 = call i64 @calc_pext_u64(i64 %13, i64 %16)
store i64 %17, i64* %4
%18 = load i64, i64* %2
%19 = load i64, i64* %1
%20 = mul i64 %19, 3
%21 = xor i64 %20, -1
%22 = call i64 @_pext_u64(i64 %18, i64 %21)
store i64 %22, i64* %3
%23 = load i64, i64* %3
%24 = load i64, i64* %4
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %8
%27 = call i32 (...) @abort()
unreachable
28: ; preds = %8
br label %29
29: ; preds = %28
%30 = load i64, i64* %1
%31 = add i64 %30, 1
store i64 %31, i64* %1
br label %5
32: ; preds = %5
ret void
}

LLVM IR (-O2):
define void @bmi2_test() {
%1 = tail call i64 @calc_pext_u64(i64 929901850898786220, i64 -1)
%2 = tail call i64 @_pext_u64(i64 929901850898786220, i64 -1)
%3 = icmp eq i64 %2, %1
br i1 %3, label %4, label %20
4: ; preds = %0
%5 = tail call i64 @calc_pext_u64(i64 1859803701797572440, i64 -4)
%6 = tail call i64 @_pext_u64(i64 1859803701797572440, i64 -4)
%7 = icmp eq i64 %6, %5
br i1 %7, label %8, label %20
8: ; preds = %4
%9 = tail call i64 @calc_pext_u64(i64 5579411105392717320, i64 -7)
%10 = tail call i64 @_pext_u64(i64 5579411105392717320, i64 -7)
%11 = icmp eq i64 %10, %9
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = tail call i64 @calc_pext_u64(i64 3870900347861317664, i64 -10)
%14 = tail call i64 @_pext_u64(i64 3870900347861317664, i64 -10)
%15 = icmp eq i64 %14, %13
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = tail call i64 @calc_pext_u64(i64 907757665597036704, i64 -13)
%18 = tail call i64 @_pext_u64(i64 907757665597036704, i64 -13)
%19 = icmp eq i64 %18, %17
br i1 %19, label %22, label %20
20: ; preds = %16, %12, %8, %4, %0
%21 = tail call i32 (...) @abort()
unreachable
22: ; preds = %16
ret void
}