#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 __blsmsk_u64(long long);
int /*<<< orphan*/ abort();
long long calc_blsmsk_u64(long long, long long);
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_blsmsk_u64(src, src);
    res = __blsmsk_u64(src);
    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    11ae <bmi_test+0x7e>
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
call   1040 <calc_blsmsk_u64@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <__blsmsk_u64@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     119b <bmi_test+0x6b>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    11a0 <bmi_test+0x70>
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   %r14
push   %rbx
push   %rax
movabs $0xfacec0ffeefacec0,%r14
c0 ce fa
mov    %r14,%rdi
mov    %r14,%rsi
call   1040 <calc_blsmsk_u64@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <__blsmsk_u64@plt>
cmp    %rbx,%rax
jne    11f9 <bmi_test+0xc9>
movabs $0xf59d81ffddf59d82,%r14
81 9d f5
mov    %r14,%rdi
mov    %r14,%rsi
call   1040 <calc_blsmsk_u64@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <__blsmsk_u64@plt>
cmp    %rbx,%rax
jne    11f9 <bmi_test+0xc9>
movabs $0xd67607ff77d67610,%r14
07 76 d6
mov    %r14,%rdi
mov    %r14,%rsi
call   1040 <calc_blsmsk_u64@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <__blsmsk_u64@plt>
cmp    %rbx,%rax
jne    11f9 <bmi_test+0xc9>
movabs $0xb3b03ffbbeb3b098,%r14
3f b0 b3
mov    %r14,%rdi
mov    %r14,%rsi
call   1040 <calc_blsmsk_u64@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <__blsmsk_u64@plt>
cmp    %rbx,%rax
jne    11f9 <bmi_test+0xc9>
movabs $0x3b03ffbbeb3b09c0,%r14
ff 03 3b
mov    %r14,%rdi
mov    %r14,%rsi
call   1040 <calc_blsmsk_u64@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <__blsmsk_u64@plt>
cmp    %rbx,%rax
jne    11f9 <bmi_test+0xc9>
add    $0x8,%rsp
pop    %rbx
pop    %r14
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 = %27, %0
%6 = load i32, i32* %1
%7 = icmp ult i32 %6, 5
br i1 %7, label %8, label %30
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 = call i64 @calc_blsmsk_u64(i64 %16, i64 %17)
store i64 %18, i64* %4
%19 = load i64, i64* %2
%20 = call i64 @__blsmsk_u64(i64 %19)
store i64 %20, i64* %3
%21 = load i64, i64* %3
%22 = load i64, i64* %4
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %8
%25 = call i32 (...) @abort()
unreachable
26: ; preds = %8
br label %27
27: ; preds = %26
%28 = load i32, i32* %1
%29 = add i32 %28, 1
store i32 %29, i32* %1
br label %5
30: ; preds = %5
ret void
}

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