#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 */
int /*<<< orphan*/ abort();
unsigned long long calc_mul_u32(unsigned int, unsigned int);
unsigned long long gen_mulx(unsigned int, unsigned int);
void bmi2_test() {
  unsigned i;
  unsigned a = 0xce7ace0;
  unsigned b = 0xfacefff;
  unsigned long long res, res_ref;
  for (i = 0; i < 5; ++i) {
    a = a * (i + 1);
    b = b / (i + 1);
    res_ref = calc_mul_u32(a, b);
    res = gen_mulx(a, b);
    if (res != res_ref)
      abort();
  }
}


x86 assembly (clang, -O0):
<bmi2_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xce7ace0,-0x8(%rbp)
movl   $0xfacefff,-0xc(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x5,-0x4(%rbp)
jae    11bc <bmi2_test+0x8c>
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
imul   %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <calc_mul_u32@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <gen_mulx@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     11a9 <bmi2_test+0x79>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    11ae <bmi2_test+0x7e>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    114d <bmi2_test+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bmi2_test>:
push   %rbx
mov    $0xce7ace0,%edi
mov    $0xfacefff,%esi
call   1030 <calc_mul_u32@plt>
mov    %rax,%rbx
mov    $0xce7ace0,%edi
mov    $0xfacefff,%esi
call   1050 <gen_mulx@plt>
cmp    %rbx,%rax
jne    11f5 <bmi2_test+0xc5>
mov    $0x19cf59c0,%edi
mov    $0x7d677ff,%esi
call   1030 <calc_mul_u32@plt>
mov    %rax,%rbx
mov    $0x19cf59c0,%edi
mov    $0x7d677ff,%esi
call   1050 <gen_mulx@plt>
cmp    %rbx,%rax
jne    11f5 <bmi2_test+0xc5>
mov    $0x4d6e0d40,%edi
mov    $0x29cd2aa,%esi
call   1030 <calc_mul_u32@plt>
mov    %rax,%rbx
mov    $0x4d6e0d40,%edi
mov    $0x29cd2aa,%esi
call   1050 <gen_mulx@plt>
cmp    %rbx,%rax
jne    11f5 <bmi2_test+0xc5>
mov    $0x35b83500,%edi
mov    $0xa734aa,%esi
call   1030 <calc_mul_u32@plt>
mov    %rax,%rbx
mov    $0x35b83500,%edi
mov    $0xa734aa,%esi
call   1050 <gen_mulx@plt>
cmp    %rbx,%rax
jne    11f5 <bmi2_test+0xc5>
mov    $0xc990900,%edi
mov    $0x2170ee,%esi
call   1030 <calc_mul_u32@plt>
mov    %rax,%rbx
mov    $0xc990900,%edi
mov    $0x2170ee,%esi
call   1050 <gen_mulx@plt>
cmp    %rbx,%rax
jne    11f5 <bmi2_test+0xc5>
pop    %rbx
ret
xor    %eax,%eax
call   1040 <abort@plt>

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

LLVM IR (-O2):
define void @bmi2_test() {
%1 = tail call i64 @calc_mul_u32(i32 216509664, i32 262991871)
%2 = tail call i64 @gen_mulx(i32 216509664, i32 262991871)
%3 = icmp eq i64 %2, %1
br i1 %3, label %4, label %20
4: ; preds = %0
%5 = tail call i64 @calc_mul_u32(i32 433019328, i32 131495935)
%6 = tail call i64 @gen_mulx(i32 433019328, i32 131495935)
%7 = icmp eq i64 %6, %5
br i1 %7, label %8, label %20
8: ; preds = %4
%9 = tail call i64 @calc_mul_u32(i32 1299057984, i32 43831978)
%10 = tail call i64 @gen_mulx(i32 1299057984, i32 43831978)
%11 = icmp eq i64 %10, %9
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = tail call i64 @calc_mul_u32(i32 901264640, i32 10957994)
%14 = tail call i64 @gen_mulx(i32 901264640, i32 10957994)
%15 = icmp eq i64 %14, %13
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = tail call i64 @calc_mul_u32(i32 211355904, i32 2191598)
%18 = tail call i64 @gen_mulx(i32 211355904, i32 2191598)
%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
}