#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 __tzcnt_u32(int);
int /*<<< orphan*/ abort();
int calc_tzcnt_u32(int);
void bmi_test() {
  unsigned i;
  int src = 0xfacec0ff;
  int res, res_ref;
  for (i = 0; i < 5; ++i) {
    src = i + (src << i);
    res_ref = calc_tzcnt_u32(src);
    res = __tzcnt_u32(src);
    if (res != res_ref)
      abort();
  }
}


x86 assembly (clang, -O0):
<bmi_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xfacec0ff,-0x8(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x5,-0x4(%rbp)
jae    119e <bmi_test+0x6e>
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%edx
mov    -0x4(%rbp),%ecx
shl    %cl,%edx
mov    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <calc_tzcnt_u32@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <__tzcnt_u32@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     118b <bmi_test+0x5b>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1190 <bmi_test+0x60>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1146 <bmi_test+0x16>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bmi_test>:
push   %rbx
mov    $0xfacec0ff,%edi
call   1040 <calc_tzcnt_u32@plt>
mov    %eax,%ebx
mov    $0xfacec0ff,%edi
call   1050 <__tzcnt_u32@plt>
cmp    %ebx,%eax
jne    11b5 <bmi_test+0x85>
mov    $0xf59d81ff,%edi
call   1040 <calc_tzcnt_u32@plt>
mov    %eax,%ebx
mov    $0xf59d81ff,%edi
call   1050 <__tzcnt_u32@plt>
cmp    %ebx,%eax
jne    11b5 <bmi_test+0x85>
mov    $0xd67607fe,%edi
call   1040 <calc_tzcnt_u32@plt>
mov    %eax,%ebx
mov    $0xd67607fe,%edi
call   1050 <__tzcnt_u32@plt>
cmp    %ebx,%eax
jne    11b5 <bmi_test+0x85>
mov    $0xb3b03ff3,%edi
call   1040 <calc_tzcnt_u32@plt>
mov    %eax,%ebx
mov    $0xb3b03ff3,%edi
call   1050 <__tzcnt_u32@plt>
cmp    %ebx,%eax
jne    11b5 <bmi_test+0x85>
mov    $0x3b03ff34,%edi
call   1040 <calc_tzcnt_u32@plt>
mov    %eax,%ebx
mov    $0x3b03ff34,%edi
call   1050 <__tzcnt_u32@plt>
cmp    %ebx,%eax
jne    11b5 <bmi_test+0x85>
pop    %rbx
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
define void @bmi_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 -87113473, i32* %2
store i32 0, i32* %1
br label %5
5: ; preds = %24, %0
%6 = load i32, i32* %1
%7 = icmp ult i32 %6, 5
br i1 %7, label %8, label %27
8: ; preds = %5
%9 = load i32, i32* %1
%10 = load i32, i32* %2
%11 = load i32, i32* %1
%12 = shl i32 %10, %11
%13 = add i32 %9, %12
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = call i32 @calc_tzcnt_u32(i32 %14)
store i32 %15, i32* %4
%16 = load i32, i32* %2
%17 = call i32 @__tzcnt_u32(i32 %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %8
%22 = call i32 (...) @abort()
unreachable
23: ; preds = %8
br label %24
24: ; preds = %23
%25 = load i32, i32* %1
%26 = add i32 %25, 1
store i32 %26, i32* %1
br label %5
27: ; preds = %5
ret void
}

LLVM IR (-O2):
define void @bmi_test() {
%1 = tail call i32 @calc_tzcnt_u32(i32 -87113473)
%2 = tail call i32 @__tzcnt_u32(i32 -87113473)
%3 = icmp eq i32 %2, %1
br i1 %3, label %4, label %21
4: ; preds = %0
%5 = tail call i32 @calc_tzcnt_u32(i32 -174226945)
%6 = tail call i32 @__tzcnt_u32(i32 -174226945)
%7 = icmp eq i32 %6, %5
br i1 %7, label %8, label %21
8: ; preds = %4
%9 = tail call i32 @calc_tzcnt_u32(i32 -696907778)
%10 = tail call i32 @__tzcnt_u32(i32 -696907778)
%11 = icmp eq i32 %10, %9
br i1 %11, label %12, label %21
12: ; preds = %8
%13 = tail call i32 @calc_tzcnt_u32(i32 -1280294925)
%14 = tail call i32 @__tzcnt_u32(i32 -1280294925)
%15 = icmp eq i32 %14, %13
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = tail call i32 @calc_tzcnt_u32(i32 990117684)
%18 = tail call i32 @__tzcnt_u32(i32 990117684)
%19 = icmp eq i32 %18, %17
br i1 %19, label %20, label %21
20: ; preds = %16
ret void
21: ; preds = %16, %12, %8, %4, %0
%22 = tail call i32 (...) @abort()
unreachable
}