#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 int _pext_u32(unsigned int, unsigned int);
int /*<<< orphan*/ abort();
unsigned int calc_pext_u32(unsigned int, unsigned int);
void bmi2_test() {
  unsigned i;
  unsigned src = 0xce7acc;
  unsigned res, res_ref;
  for (i = 0; i < 5; ++i) {
    src = src * (i + 1);
    res_ref = calc_pext_u32(src, ~(i * 3));
    res = _pext_u32(src, ~(i * 3));
    if (res != res_ref)
      abort();
  }
}


x86 assembly (clang, -O0):
<bmi2_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xce7acc,-0x8(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x5,-0x4(%rbp)
jae    11a9 <bmi2_test+0x79>
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
imul   %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
imul   $0x3,-0x4(%rbp),%esi
xor    $0xffffffff,%esi
call   1040 <calc_pext_u32@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
imul   $0x3,-0x4(%rbp),%esi
xor    $0xffffffff,%esi
call   1050 <_pext_u32@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     1196 <bmi2_test+0x66>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    119b <bmi2_test+0x6b>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1146 <bmi2_test+0x16>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bmi2_test>:
push   %rbx
mov    $0xce7acc,%edi
mov    $0xffffffff,%esi
call   1040 <calc_pext_u32@plt>
mov    %eax,%ebx
mov    $0xce7acc,%edi
mov    $0xffffffff,%esi
call   1050 <_pext_u32@plt>
cmp    %ebx,%eax
jne    11eb <bmi2_test+0xbb>
mov    $0x19cf598,%edi
mov    $0xfffffffc,%esi
call   1040 <calc_pext_u32@plt>
mov    %eax,%ebx
mov    $0x19cf598,%edi
mov    $0xfffffffc,%esi
call   1050 <_pext_u32@plt>
cmp    %ebx,%eax
jne    11eb <bmi2_test+0xbb>
mov    $0x4d6e0c8,%edi
mov    $0xfffffff9,%esi
call   1040 <calc_pext_u32@plt>
mov    %eax,%ebx
mov    $0x4d6e0c8,%edi
mov    $0xfffffff9,%esi
call   1050 <_pext_u32@plt>
cmp    %ebx,%eax
jne    11eb <bmi2_test+0xbb>
mov    $0x135b8320,%edi
mov    $0xfffffff6,%esi
call   1040 <calc_pext_u32@plt>
mov    %eax,%ebx
mov    $0x135b8320,%edi
mov    $0xfffffff6,%esi
call   1050 <_pext_u32@plt>
cmp    %ebx,%eax
jne    11eb <bmi2_test+0xbb>
mov    $0x60c98fa0,%edi
mov    $0xfffffff3,%esi
call   1040 <calc_pext_u32@plt>
mov    %eax,%ebx
mov    $0x60c98fa0,%edi
mov    $0xfffffff3,%esi
call   1050 <_pext_u32@plt>
cmp    %ebx,%eax
jne    11eb <bmi2_test+0xbb>
pop    %rbx
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
define void @bmi2_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 13531852, i32* %2
store i32 0, i32* %1
br label %5
5: ; preds = %29, %0
%6 = load i32, i32* %1
%7 = icmp ult i32 %6, 5
br i1 %7, label %8, label %32
8: ; preds = %5
%9 = load i32, i32* %2
%10 = load i32, i32* %1
%11 = add i32 %10, 1
%12 = mul i32 %9, %11
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = load i32, i32* %1
%15 = mul i32 %14, 3
%16 = xor i32 %15, -1
%17 = call i32 @calc_pext_u32(i32 %13, i32 %16)
store i32 %17, i32* %4
%18 = load i32, i32* %2
%19 = load i32, i32* %1
%20 = mul i32 %19, 3
%21 = xor i32 %20, -1
%22 = call i32 @_pext_u32(i32 %18, i32 %21)
store i32 %22, i32* %3
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = icmp ne i32 %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 i32, i32* %1
%31 = add i32 %30, 1
store i32 %31, i32* %1
br label %5
32: ; preds = %5
ret void
}

LLVM IR (-O2):
define void @bmi2_test() {
%1 = tail call i32 @calc_pext_u32(i32 13531852, i32 -1)
%2 = tail call i32 @_pext_u32(i32 13531852, i32 -1)
%3 = icmp eq i32 %2, %1
br i1 %3, label %4, label %20
4: ; preds = %0
%5 = tail call i32 @calc_pext_u32(i32 27063704, i32 -4)
%6 = tail call i32 @_pext_u32(i32 27063704, i32 -4)
%7 = icmp eq i32 %6, %5
br i1 %7, label %8, label %20
8: ; preds = %4
%9 = tail call i32 @calc_pext_u32(i32 81191112, i32 -7)
%10 = tail call i32 @_pext_u32(i32 81191112, i32 -7)
%11 = icmp eq i32 %10, %9
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = tail call i32 @calc_pext_u32(i32 324764448, i32 -10)
%14 = tail call i32 @_pext_u32(i32 324764448, i32 -10)
%15 = icmp eq i32 %14, %13
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = tail call i32 @calc_pext_u32(i32 1623822240, i32 -13)
%18 = tail call i32 @_pext_u32(i32 1623822240, i32 -13)
%19 = icmp eq i32 %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
}