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


x86 assembly (clang, -O0):
<bmi_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movabs $0xfacec0ffeefacec0,%rax
c0 ce fa
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x5,-0x4(%rbp)
jae    11c0 <bmi_test+0x90>
mov    -0x4(%rbp),%eax
add    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
shl    %cl,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%eax
add    %rax,%rsi
xor    %edx,%edx
call   1050 <calc_andn_u64@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%eax
add    %rax,%rsi
call   1040 <__andn_u64@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     11ad <bmi_test+0x7d>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    11b2 <bmi_test+0x82>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    114d <bmi_test+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bmi_test>:
push   %r15
push   %r14
push   %rbx
movabs $0xfacec0ffeefacec0,%rbx
c0 ce fa
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1050 <calc_andn_u64@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1040 <__andn_u64@plt>
cmp    %r14,%rax
jne    1225 <bmi_test+0xf5>
movabs $0xf59d81ffddf59d82,%r14
81 9d f5
lea    0x1(%r14),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1050 <calc_andn_u64@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <__andn_u64@plt>
cmp    %r15,%rax
jne    1225 <bmi_test+0xf5>
movabs $0xd67607ff77d67610,%r14
07 76 d6
lea    0x2(%r14),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1050 <calc_andn_u64@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <__andn_u64@plt>
cmp    %r15,%rax
jne    1225 <bmi_test+0xf5>
movabs $0xb3b03ffbbeb3b098,%r14
3f b0 b3
lea    0x3(%r14),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1050 <calc_andn_u64@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <__andn_u64@plt>
cmp    %r15,%rax
jne    1225 <bmi_test+0xf5>
movabs $0x3b03ffbbeb3b09c0,%r14
ff 03 3b
lea    0x4(%r14),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1050 <calc_andn_u64@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <__andn_u64@plt>
cmp    %r15,%rax
jne    1225 <bmi_test+0xf5>
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
define void @bmi_test() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 -374149513566564672, i64* %2
store i32 0, i32* %1
br label %5
5: ; preds = %34, %0
%6 = load i32, i32* %1
%7 = icmp ult i32 %6, 5
br i1 %7, label %8, label %37
8: ; preds = %5
%9 = load i32, i32* %1
%10 = zext i32 %9 to i64
%11 = load i64, i64* %2
%12 = add nsw i64 %10, %11
%13 = load i32, i32* %1
%14 = zext i32 %13 to i64
%15 = shl i64 %12, %14
store i64 %15, i64* %2
%16 = load i64, i64* %2
%17 = load i64, i64* %2
%18 = load i32, i32* %1
%19 = zext i32 %18 to i64
%20 = add nsw i64 %17, %19
%21 = call i64 @calc_andn_u64(i64 %16, i64 %20, i32 0)
store i64 %21, i64* %4
%22 = load i64, i64* %2
%23 = load i64, i64* %2
%24 = load i32, i32* %1
%25 = zext i32 %24 to i64
%26 = add nsw i64 %23, %25
%27 = call i64 @__andn_u64(i64 %22, i64 %26)
store i64 %27, i64* %3
%28 = load i64, i64* %3
%29 = load i64, i64* %4
%30 = icmp ne i64 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %8
%32 = call i32 (...) @abort()
unreachable
33: ; preds = %8
br label %34
34: ; preds = %33
%35 = load i32, i32* %1
%36 = add i32 %35, 1
store i32 %36, i32* %1
br label %5
37: ; preds = %5
ret void
}

LLVM IR (-O2):
define void @bmi_test() {
%1 = tail call i64 @calc_andn_u64(i64 -374149513566564672, i64 -374149513566564672, i32 0)
%2 = tail call i64 @__andn_u64(i64 -374149513566564672, i64 -374149513566564672)
%3 = icmp eq i64 %2, %1
br i1 %3, label %4, label %21
4: ; preds = %0
%5 = tail call i64 @calc_andn_u64(i64 -748299027133129342, i64 -748299027133129341, i32 0)
%6 = tail call i64 @__andn_u64(i64 -748299027133129342, i64 -748299027133129341)
%7 = icmp eq i64 %6, %5
br i1 %7, label %8, label %21
8: ; preds = %4
%9 = tail call i64 @calc_andn_u64(i64 -2993196108532517360, i64 -2993196108532517358, i32 0)
%10 = tail call i64 @__andn_u64(i64 -2993196108532517360, i64 -2993196108532517358)
%11 = icmp eq i64 %10, %9
br i1 %11, label %12, label %21
12: ; preds = %8
%13 = tail call i64 @calc_andn_u64(i64 -5498824794550587240, i64 -5498824794550587237, i32 0)
%14 = tail call i64 @__andn_u64(i64 -5498824794550587240, i64 -5498824794550587237)
%15 = icmp eq i64 %14, %13
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = tail call i64 @calc_andn_u64(i64 4252523655738362304, i64 4252523655738362308, i32 0)
%18 = tail call i64 @__andn_u64(i64 4252523655738362304, i64 4252523655738362308)
%19 = icmp eq i64 %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
}