#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 __tzcnt_u64(long long);
int /*<<< orphan*/ abort();
long long calc_tzcnt_u64(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_tzcnt_u64(src);
    res = __tzcnt_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    11aa <bmi_test+0x7a>
mov    -0x4(%rbp),%eax
add    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
shl    %cl,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <calc_tzcnt_u64@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <__tzcnt_u64@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     1197 <bmi_test+0x67>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    119c <bmi_test+0x6c>
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
call   1040 <calc_tzcnt_u64@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <__tzcnt_u64@plt>
cmp    %rbx,%rax
jne    11ea <bmi_test+0xba>
movabs $0xf59d81ffddf59d82,%r14
81 9d f5
mov    %r14,%rdi
call   1040 <calc_tzcnt_u64@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <__tzcnt_u64@plt>
cmp    %rbx,%rax
jne    11ea <bmi_test+0xba>
movabs $0xd67607ff77d67610,%r14
07 76 d6
mov    %r14,%rdi
call   1040 <calc_tzcnt_u64@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <__tzcnt_u64@plt>
cmp    %rbx,%rax
jne    11ea <bmi_test+0xba>
movabs $0xb3b03ffbbeb3b098,%r14
3f b0 b3
mov    %r14,%rdi
call   1040 <calc_tzcnt_u64@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <__tzcnt_u64@plt>
cmp    %rbx,%rax
jne    11ea <bmi_test+0xba>
movabs $0x3b03ffbbeb3b09c0,%r14
ff 03 3b
mov    %r14,%rdi
call   1040 <calc_tzcnt_u64@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <__tzcnt_u64@plt>
cmp    %rbx,%rax
jne    11ea <bmi_test+0xba>
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 = %26, %0
%6 = load i32, i32* %1
%7 = icmp ult i32 %6, 5
br i1 %7, label %8, label %29
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 = call i64 @calc_tzcnt_u64(i64 %16)
store i64 %17, i64* %4
%18 = load i64, i64* %2
%19 = call i64 @__tzcnt_u64(i64 %18)
store i64 %19, i64* %3
%20 = load i64, i64* %3
%21 = load i64, i64* %4
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %8
%24 = call i32 (...) @abort()
unreachable
25: ; preds = %8
br label %26
26: ; preds = %25
%27 = load i32, i32* %1
%28 = add i32 %27, 1
store i32 %28, i32* %1
br label %5
29: ; preds = %5
ret void
}

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