#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 __blsr_u32(int);
int /*<<< orphan*/ abort();
int calc_blsr_u32(int, 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_blsr_u32(src, src);
    res = __blsr_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    119d <bmi_test+0x6d>
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
shl    %cl,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <calc_blsr_u32@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <__blsr_u32@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     118a <bmi_test+0x5a>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    118f <bmi_test+0x5f>
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
mov    $0xfacec0ff,%esi
call   1040 <calc_blsr_u32@plt>
mov    %eax,%ebx
mov    $0xfacec0ff,%edi
call   1050 <__blsr_u32@plt>
cmp    %ebx,%eax
jne    11ce <bmi_test+0x9e>
mov    $0xf59d8200,%edi
mov    $0xf59d8200,%esi
call   1040 <calc_blsr_u32@plt>
mov    %eax,%ebx
mov    $0xf59d8200,%edi
call   1050 <__blsr_u32@plt>
cmp    %ebx,%eax
jne    11ce <bmi_test+0x9e>
mov    $0xd6760808,%edi
mov    $0xd6760808,%esi
call   1040 <calc_blsr_u32@plt>
mov    %eax,%ebx
mov    $0xd6760808,%edi
call   1050 <__blsr_u32@plt>
cmp    %ebx,%eax
jne    11ce <bmi_test+0x9e>
mov    $0xb3b04058,%edi
mov    $0xb3b04058,%esi
call   1040 <calc_blsr_u32@plt>
mov    %eax,%ebx
mov    $0xb3b04058,%edi
call   1050 <__blsr_u32@plt>
cmp    %ebx,%eax
jne    11ce <bmi_test+0x9e>
mov    $0x3b0405c0,%edi
mov    $0x3b0405c0,%esi
call   1040 <calc_blsr_u32@plt>
mov    %eax,%ebx
mov    $0x3b0405c0,%edi
call   1050 <__blsr_u32@plt>
cmp    %ebx,%eax
jne    11ce <bmi_test+0x9e>
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 = %25, %0
%6 = load i32, i32* %1
%7 = icmp ult i32 %6, 5
br i1 %7, label %8, label %28
8: ; preds = %5
%9 = load i32, i32* %1
%10 = load i32, i32* %2
%11 = add i32 %9, %10
%12 = load i32, i32* %1
%13 = shl i32 %11, %12
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = load i32, i32* %2
%16 = call i32 @calc_blsr_u32(i32 %14, i32 %15)
store i32 %16, i32* %4
%17 = load i32, i32* %2
%18 = call i32 @__blsr_u32(i32 %17)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = load i32, i32* %4
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %8
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %8
br label %25
25: ; preds = %24
%26 = load i32, i32* %1
%27 = add i32 %26, 1
store i32 %27, i32* %1
br label %5
28: ; preds = %5
ret void
}

LLVM IR (-O2):
define void @bmi_test() {
%1 = tail call i32 @calc_blsr_u32(i32 -87113473, i32 -87113473)
%2 = tail call i32 @__blsr_u32(i32 -87113473)
%3 = icmp eq i32 %2, %1
br i1 %3, label %4, label %21
4: ; preds = %0
%5 = tail call i32 @calc_blsr_u32(i32 -174226944, i32 -174226944)
%6 = tail call i32 @__blsr_u32(i32 -174226944)
%7 = icmp eq i32 %6, %5
br i1 %7, label %8, label %21
8: ; preds = %4
%9 = tail call i32 @calc_blsr_u32(i32 -696907768, i32 -696907768)
%10 = tail call i32 @__blsr_u32(i32 -696907768)
%11 = icmp eq i32 %10, %9
br i1 %11, label %12, label %21
12: ; preds = %8
%13 = tail call i32 @calc_blsr_u32(i32 -1280294824, i32 -1280294824)
%14 = tail call i32 @__blsr_u32(i32 -1280294824)
%15 = icmp eq i32 %14, %13
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = tail call i32 @calc_blsr_u32(i32 990119360, i32 990119360)
%18 = tail call i32 @__blsr_u32(i32 990119360)
%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
}