#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 __andn_u32(int, int);
int /*<<< orphan*/ abort();
int calc_andn_u32(int, int, int /*<<< orphan*/);
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_andn_u32(src, src + i, 0);
    res = __andn_u32(src, src + i);
    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    11a8 <bmi_test+0x78>
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
add    -0x4(%rbp),%esi
xor    %edx,%edx
call   1050 <calc_andn_u32@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
add    -0x4(%rbp),%esi
call   1040 <__andn_u32@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     1195 <bmi_test+0x65>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    119a <bmi_test+0x6a>
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
xor    %edx,%edx
call   1050 <calc_andn_u32@plt>
mov    %eax,%ebx
mov    $0xfacec0ff,%edi
mov    $0xfacec0ff,%esi
call   1040 <__andn_u32@plt>
cmp    %ebx,%eax
jne    11f5 <bmi_test+0xc5>
mov    $0xf59d8200,%edi
mov    $0xf59d8201,%esi
xor    %edx,%edx
call   1050 <calc_andn_u32@plt>
mov    %eax,%ebx
mov    $0xf59d8200,%edi
mov    $0xf59d8201,%esi
call   1040 <__andn_u32@plt>
cmp    %ebx,%eax
jne    11f5 <bmi_test+0xc5>
mov    $0xd6760808,%edi
mov    $0xd676080a,%esi
xor    %edx,%edx
call   1050 <calc_andn_u32@plt>
mov    %eax,%ebx
mov    $0xd6760808,%edi
mov    $0xd676080a,%esi
call   1040 <__andn_u32@plt>
cmp    %ebx,%eax
jne    11f5 <bmi_test+0xc5>
mov    $0xb3b04058,%edi
mov    $0xb3b0405b,%esi
xor    %edx,%edx
call   1050 <calc_andn_u32@plt>
mov    %eax,%ebx
mov    $0xb3b04058,%edi
mov    $0xb3b0405b,%esi
call   1040 <__andn_u32@plt>
cmp    %ebx,%eax
jne    11f5 <bmi_test+0xc5>
mov    $0x3b0405c0,%edi
mov    $0x3b0405c4,%esi
xor    %edx,%edx
call   1050 <calc_andn_u32@plt>
mov    %eax,%ebx
mov    $0x3b0405c0,%edi
mov    $0x3b0405c4,%esi
call   1040 <__andn_u32@plt>
cmp    %ebx,%eax
jne    11f5 <bmi_test+0xc5>
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 = %30, %0
%6 = load i32, i32* %1
%7 = icmp ult i32 %6, 5
br i1 %7, label %8, label %33
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 = load i32, i32* %1
%17 = add i32 %15, %16
%18 = call i32 @calc_andn_u32(i32 %14, i32 %17, i32 0)
store i32 %18, i32* %4
%19 = load i32, i32* %2
%20 = load i32, i32* %2
%21 = load i32, i32* %1
%22 = add i32 %20, %21
%23 = call i32 @__andn_u32(i32 %19, i32 %22)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %8
%28 = call i32 (...) @abort()
unreachable
29: ; preds = %8
br label %30
30: ; preds = %29
%31 = load i32, i32* %1
%32 = add i32 %31, 1
store i32 %32, i32* %1
br label %5
33: ; preds = %5
ret void
}

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