#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 _pdep_u32(unsigned int, unsigned int);
int /*<<< orphan*/ abort();
unsigned int calc_pdep_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_pdep_u32(src, i * 3);
    res = _pdep_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    11a3 <bmi2_test+0x73>
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
call   1040 <calc_pdep_u32@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
imul   $0x3,-0x4(%rbp),%esi
call   1050 <_pdep_u32@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     1190 <bmi2_test+0x60>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1195 <bmi2_test+0x65>
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
xor    %esi,%esi
call   1040 <calc_pdep_u32@plt>
mov    %eax,%ebx
mov    $0xce7acc,%edi
xor    %esi,%esi
call   1050 <_pdep_u32@plt>
cmp    %ebx,%eax
jne    11e5 <bmi2_test+0xb5>
mov    $0x19cf598,%edi
mov    $0x3,%esi
call   1040 <calc_pdep_u32@plt>
mov    %eax,%ebx
mov    $0x19cf598,%edi
mov    $0x3,%esi
call   1050 <_pdep_u32@plt>
cmp    %ebx,%eax
jne    11e5 <bmi2_test+0xb5>
mov    $0x4d6e0c8,%edi
mov    $0x6,%esi
call   1040 <calc_pdep_u32@plt>
mov    %eax,%ebx
mov    $0x4d6e0c8,%edi
mov    $0x6,%esi
call   1050 <_pdep_u32@plt>
cmp    %ebx,%eax
jne    11e5 <bmi2_test+0xb5>
mov    $0x135b8320,%edi
mov    $0x9,%esi
call   1040 <calc_pdep_u32@plt>
mov    %eax,%ebx
mov    $0x135b8320,%edi
mov    $0x9,%esi
call   1050 <_pdep_u32@plt>
cmp    %ebx,%eax
jne    11e5 <bmi2_test+0xb5>
mov    $0x60c98fa0,%edi
mov    $0xc,%esi
call   1040 <calc_pdep_u32@plt>
mov    %eax,%ebx
mov    $0x60c98fa0,%edi
mov    $0xc,%esi
call   1050 <_pdep_u32@plt>
cmp    %ebx,%eax
jne    11e5 <bmi2_test+0xb5>
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 = %27, %0
%6 = load i32, i32* %1
%7 = icmp ult i32 %6, 5
br i1 %7, label %8, label %30
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 = call i32 @calc_pdep_u32(i32 %13, i32 %15)
store i32 %16, i32* %4
%17 = load i32, i32* %2
%18 = load i32, i32* %1
%19 = mul i32 %18, 3
%20 = call i32 @_pdep_u32(i32 %17, i32 %19)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %8
%25 = call i32 (...) @abort()
unreachable
26: ; preds = %8
br label %27
27: ; preds = %26
%28 = load i32, i32* %1
%29 = add i32 %28, 1
store i32 %29, i32* %1
br label %5
30: ; preds = %5
ret void
}

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