int main() {
  volatile long a = 0x0000000000000001L;
  if (__builtin_ctzl(a) != 0) {
    return 1;
  }
  volatile long b = 0x0000000000000002;
  if (__builtin_ctzl(b) != 1) {
    return 1;
  }
  volatile long c = 0x0000000080000000;
  if (__builtin_ctzl(c) != 31) {
    return 1;
  }
  volatile long d = 0x0000000100000000;
  if (__builtin_ctzl(d) != 32) {
    return 1;
  }
  volatile long e = 0x8000000000000000;
  if (__builtin_ctzl(e) != 63) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
movl   $0x0,-0x4(%rbp)
movq   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%rax
bsf    %rax,%rax
cmp    $0x0,%eax
je     1130 <main+0x30>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <main+0xd8>
movq   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%rax
bsf    %rax,%rax
cmp    $0x1,%eax
je     1155 <main+0x55>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <main+0xd8>
mov    $0x80000000,%eax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
bsf    %rax,%rax
cmp    $0x1f,%eax
je     117b <main+0x7b>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <main+0xd8>
movabs $0x100000000,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
bsf    %rax,%rax
cmp    $0x20,%eax
je     11a6 <main+0xa6>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <main+0xd8>
movabs $0x8000000000000000,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
bsf    %rax,%rax
cmp    $0x3f,%eax
je     11d1 <main+0xd1>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <main+0xd8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
movq   $0x1,-0x8(%rsp)
mov    $0x1,%eax
testq  $0x1,-0x8(%rsp)
je     1194 <main+0x94>
movq   $0x2,-0x10(%rsp)
mov    -0x10(%rsp),%rcx
and    $0x3,%ecx
mov    $0x1,%eax
cmp    $0x2,%ecx
jne    1194 <main+0x94>
mov    $0x80000000,%eax
mov    %rax,-0x18(%rsp)
mov    -0x18(%rsp),%rcx
mov    $0x1,%eax
cmp    $0x80000000,%ecx
jne    1194 <main+0x94>
movabs $0x100000000,%rcx
mov    %rcx,-0x20(%rsp)
movabs $0x1ffffffff,%rdx
and    -0x20(%rsp),%rdx
mov    $0x1,%eax
cmp    %rcx,%rdx
jne    1194 <main+0x94>
movabs $0x8000000000000000,%rcx
mov    %rcx,-0x28(%rsp)
mov    -0x28(%rsp),%rdx
xor    %eax,%eax
cmp    %rcx,%rdx
setne  %al
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i32 0, i32* %1
store volatile i64 1, i64* %2
%7 = load volatile i64, i64* %2
%8 = call i64 @llvm.cttz.i64(i64 %7, i1 true)
%9 = trunc i64 %8 to i32
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %0
store i32 1, i32* %1
br label %37
12: ; preds = %0
store volatile i64 2, i64* %3
%13 = load volatile i64, i64* %3
%14 = call i64 @llvm.cttz.i64(i64 %13, i1 true)
%15 = trunc i64 %14 to i32
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 1, i32* %1
br label %37
18: ; preds = %12
store volatile i64 2147483648, i64* %4
%19 = load volatile i64, i64* %4
%20 = call i64 @llvm.cttz.i64(i64 %19, i1 true)
%21 = trunc i64 %20 to i32
%22 = icmp ne i32 %21, 31
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 1, i32* %1
br label %37
24: ; preds = %18
store volatile i64 4294967296, i64* %5
%25 = load volatile i64, i64* %5
%26 = call i64 @llvm.cttz.i64(i64 %25, i1 true)
%27 = trunc i64 %26 to i32
%28 = icmp ne i32 %27, 32
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 1, i32* %1
br label %37
30: ; preds = %24
store volatile i64 -9223372036854775808, i64* %6
%31 = load volatile i64, i64* %6
%32 = call i64 @llvm.cttz.i64(i64 %31, i1 true)
%33 = trunc i64 %32 to i32
%34 = icmp ne i32 %33, 63
br i1 %34, label %35, label %36
35: ; preds = %30
store i32 1, i32* %1
br label %37
36: ; preds = %30
store i32 0, i32* %1
br label %37
37: ; preds = %36, %35, %29, %23, %17, %11
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = bitcast i64* %1 to i8*
store volatile i64 1, i64* %1
%7 = load volatile i64, i64* %1
%8 = and i64 %7, 1
%9 = icmp eq i64 %8, 0
br i1 %9, label %36, label %10
10: ; preds = %0
%11 = bitcast i64* %2 to i8*
store volatile i64 2, i64* %2
%12 = load volatile i64, i64* %2
%13 = and i64 %12, 3
%14 = icmp eq i64 %13, 2
br i1 %14, label %15, label %34
15: ; preds = %10
%16 = bitcast i64* %3 to i8*
store volatile i64 2147483648, i64* %3
%17 = load volatile i64, i64* %3
%18 = and i64 %17, 4294967295
%19 = icmp eq i64 %18, 2147483648
br i1 %19, label %20, label %32
20: ; preds = %15
%21 = bitcast i64* %4 to i8*
store volatile i64 4294967296, i64* %4
%22 = load volatile i64, i64* %4
%23 = and i64 %22, 8589934591
%24 = icmp eq i64 %23, 4294967296
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = bitcast i64* %5 to i8*
store volatile i64 -9223372036854775808, i64* %5
%27 = load volatile i64, i64* %5
%28 = icmp ne i64 %27, -9223372036854775808
%29 = zext i1 %28 to i32
br label %30
30: ; preds = %20, %25
%31 = phi i32 [ %29, %25 ], [ 1, %20 ]
br label %32
32: ; preds = %15, %30
%33 = phi i32 [ %31, %30 ], [ 1, %15 ]
br label %34
34: ; preds = %10, %32
%35 = phi i32 [ %33, %32 ], [ 1, %10 ]
br label %36
36: ; preds = %0, %34
%37 = phi i32 [ %35, %34 ], [ 1, %0 ]
ret i32 %37
}