int ptls_fusion_is_supported_by_cpu(void) {
  unsigned leaf1_ecx, leaf7_ebx;
  {
    unsigned leaf_cnt;
    __asm__("cpuid" : "=a"(leaf_cnt) : "a"(0) : "ebx", "ecx", "edx");
    if (leaf_cnt < 7)
      return 0;
    __asm__("cpuid" : "=c"(leaf1_ecx) : "a"(1) : "ebx", "edx");
    __asm__("cpuid" : "=b"(leaf7_ebx) : "a"(7), "c"(0) : "edx");
  }
  if ((leaf7_ebx & (1 << 5)) == 0)
    return 0;
  if ((leaf1_ecx & (1 << 25)) == 0)
    return 0;
  if ((leaf1_ecx & (1 << 1)) == 0)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<ptls_fusion_is_supported_by_cpu>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
xor    %eax,%eax
cpuid
mov    %eax,-0x18(%rbp)
cmpl   $0x7,-0x18(%rbp)
jae    1122 <ptls_fusion_is_supported_by_cpu+0x22>
movl   $0x0,-0xc(%rbp)
jmp    1192 <ptls_fusion_is_supported_by_cpu+0x92>
mov    $0x1,%eax
cpuid
mov    %ecx,-0x10(%rbp)
mov    $0x7,%eax
xor    %ecx,%ecx
cpuid
mov    %ebx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
jne    1153 <ptls_fusion_is_supported_by_cpu+0x53>
movl   $0x0,-0xc(%rbp)
jmp    1192 <ptls_fusion_is_supported_by_cpu+0x92>
mov    -0x10(%rbp),%eax
and    $0x2000000,%eax
cmp    $0x0,%eax
jne    1170 <ptls_fusion_is_supported_by_cpu+0x70>
movl   $0x0,-0xc(%rbp)
jmp    1192 <ptls_fusion_is_supported_by_cpu+0x92>
mov    -0x10(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
jne    118b <ptls_fusion_is_supported_by_cpu+0x8b>
movl   $0x0,-0xc(%rbp)
jmp    1192 <ptls_fusion_is_supported_by_cpu+0x92>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<ptls_fusion_is_supported_by_cpu>:
push   %rbx
xor    %edi,%edi
xor    %eax,%eax
cpuid
cmp    $0x7,%eax
jae    1110 <ptls_fusion_is_supported_by_cpu+0x10>
mov    $0x1,%al
jmp    1128 <ptls_fusion_is_supported_by_cpu+0x28>
mov    $0x1,%eax
cpuid
mov    %ecx,%esi
mov    $0x7,%eax
xor    %ecx,%ecx
cpuid
test   $0x20,%bl
sete   %al
mov    %esi,%ecx
shl    $0x6,%ecx
shr    $0x1f,%ecx
shr    %esi
and    %ecx,%esi
test   %al,%al
cmovne %edi,%esi
mov    %esi,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @ptls_fusion_is_supported_by_cpu() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 asm "cpuid", "={ax},{ax},~{ebx},~{ecx},~{edx},~{dirflag},~{fpsr},~{flags}"(i32 0)
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = icmp ult i32 %6, 7
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 0, i32* %1
br label %27
9: ; preds = %0
%10 = call i32 asm "cpuid", "={cx},{ax},~{ebx},~{edx},~{dirflag},~{fpsr},~{flags}"(i32 1)
store i32 %10, i32* %2
%11 = call i32 asm "cpuid", "={bx},{ax},{cx},~{edx},~{dirflag},~{fpsr},~{flags}"(i32 7, i32 0)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = and i32 %12, 32
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %9
store i32 0, i32* %1
br label %27
16: ; preds = %9
%17 = load i32, i32* %2
%18 = and i32 %17, 33554432
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 0, i32* %1
br label %27
21: ; preds = %16
%22 = load i32, i32* %2
%23 = and i32 %22, 2
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 0, i32* %1
br label %27
26: ; preds = %21
store i32 1, i32* %1
br label %27
27: ; preds = %26, %25, %20, %15, %8
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
define i32 @ptls_fusion_is_supported_by_cpu() {
%1 = tail call i32 asm "cpuid", "={ax},{ax},~{ebx},~{ecx},~{edx},~{dirflag},~{fpsr},~{flags}"(i32 0)
%2 = icmp ult i32 %1, 7
br i1 %2, label %8, label %3
3: ; preds = %0
%4 = tail call i32 asm "cpuid", "={cx},{ax},~{ebx},~{edx},~{dirflag},~{fpsr},~{flags}"(i32 1)
%5 = tail call i32 asm "cpuid", "={bx},{ax},{cx},~{edx},~{dirflag},~{fpsr},~{flags}"(i32 7, i32 0)
%6 = and i32 %5, 32
%7 = icmp eq i32 %6, 0
br label %8
8: ; preds = %0, %3
%9 = phi i1 [ true, %0 ], [ %7, %3 ]
%10 = phi i32 [ undef, %0 ], [ %4, %3 ]
%11 = and i32 %10, 33554432
%12 = icmp eq i32 %11, 0
%13 = select i1 %9, i1 true, i1 %12
%14 = lshr i32 %10, 1
%15 = and i32 %14, 1
%16 = select i1 %13, i32 0, i32 %15
ret i32 %16
}