#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 */
typedef int u_int;
typedef int register_t;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ do_cpuid(int, int *);
int /*<<< orphan*/ printf(char *, char *);
int read_rflags();
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ write_rflags(int);
int main(int argc, char *argv[]) {
  int has_feature = 0;
  int vendor[3];
  char *cpu_vendor;
  u_int regs[4];
  register_t rflags;
  rflags = read_rflags();
  write_rflags(rflags ^ 0x00200000);
  if (((rflags ^ read_rflags()) & 0x00200000) != 0) {
    do_cpuid(0, regs);
    vendor[0] = regs[1];
    vendor[1] = regs[3];
    vendor[2] = regs[2];
    cpu_vendor = (char *)vendor;
    if (strncmp(cpu_vendor, "GenuineIntel", 12) == 0 ||
        strncmp(cpu_vendor, "AuthenticAMD", 12) == 0) {
      do_cpuid(0x1, regs);
      has_feature = (regs[3] & 0x10000000);
    }
  }
  printf("HyperThreading Status: %s\n", has_feature ? "YES" : "NO");
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1040 <read_rflags@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edi
xor    $0x200000,%edi
call   1030 <write_rflags@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    $0x0,%al
call   1040 <read_rflags@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
xor    %ecx,%eax
and    $0x200000,%eax
cmp    $0x0,%eax
je     1228 <main+0xd8>
lea    -0x40(%rbp),%rsi
xor    %edi,%edi
call   1070 <do_cpuid@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe29(%rip),%rsi
mov    $0xc,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
je     120a <main+0xba>
mov    -0x28(%rbp),%rdi
lea    0xe17(%rip),%rsi
mov    $0xc,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    1223 <main+0xd3>
lea    -0x40(%rbp),%rsi
mov    $0x1,%edi
call   1070 <do_cpuid@plt>
mov    -0x34(%rbp),%eax
and    $0x10000000,%eax
mov    %eax,-0x14(%rbp)
jmp    1228 <main+0xd8>
mov    -0x14(%rbp),%ecx
lea    0xe07(%rip),%rsi
lea    0xdfc(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xdd3(%rip),%rdi
call   1060 <printf@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
xor    %eax,%eax
call   1040 <read_rflags@plt>
mov    %eax,%ebx
mov    %eax,%edi
xor    $0x200000,%edi
call   1030 <write_rflags@plt>
xor    %eax,%eax
call   1040 <read_rflags@plt>
xor    %ebx,%eax
lea    0xebe(%rip),%rbx
test   $0x200000,%eax
je     1200 <main+0xb0>
lea    0x10(%rsp),%rsi
xor    %edi,%edi
call   1070 <do_cpuid@plt>
mov    0x14(%rsp),%eax
mov    %eax,0x4(%rsp)
mov    0x18(%rsp),%rax
rol    $0x20,%rax
mov    %rax,0x8(%rsp)
lea    0xe55(%rip),%rsi
lea    0x4(%rsp),%rdi
mov    $0xc,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
je     11da <main+0x8a>
lea    0xe47(%rip),%rsi
lea    0x4(%rsp),%rdi
mov    $0xc,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
jne    1200 <main+0xb0>
lea    0x10(%rsp),%rsi
mov    $0x1,%edi
call   1070 <do_cpuid@plt>
testb  $0x10,0x1f(%rsp)
lea    0xe44(%rip),%rax
lea    0xe39(%rip),%rbx
cmove  %rax,%rbx
lea    0xe13(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"GenuineIntel\00"
@.str.1 = [13 x i8] c"AuthenticAMD\00"
@.str.2 = [27 x i8] c"HyperThreading Status: %s\0A\00"
@.str.3 = [4 x i8] c"YES\00"
@.str.4 = [3 x i8] c"NO\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [3 x i32]
%8 = alloca i8*
%9 = alloca [4 x i32]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%11 = call i32 (...) @read_rflags()
store i32 %11, i32* %10
%12 = load i32, i32* %10
%13 = xor i32 %12, 2097152
%14 = call i32 @write_rflags(i32 %13)
%15 = load i32, i32* %10
%16 = call i32 (...) @read_rflags()
%17 = xor i32 %15, %16
%18 = and i32 %17, 2097152
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %48
20: ; preds = %2
%21 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%22 = call i32 @do_cpuid(i32 0, i32* %21)
%23 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 1
%24 = load i32, i32* %23
%25 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
store i32 %24, i32* %25
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 3
%27 = load i32, i32* %26
%28 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 1
store i32 %27, i32* %28
%29 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 2
%30 = load i32, i32* %29
%31 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 2
store i32 %30, i32* %31
%32 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
%33 = bitcast i32* %32 to i8*
store i8* %33, i8** %8
%34 = load i8*, i8** %8
%35 = call i64 @strncmp(i8* %34, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 12)
%36 = icmp eq i64 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %20
%38 = load i8*, i8** %8
%39 = call i64 @strncmp(i8* %38, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %37, %20
%42 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%43 = call i32 @do_cpuid(i32 1, i32* %42)
%44 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 3
%45 = load i32, i32* %44
%46 = and i32 %45, 268435456
store i32 %46, i32* %6
br label %47
47: ; preds = %41, %37
br label %48
48: ; preds = %47, %2
%49 = load i32, i32* %6
%50 = icmp ne i32 %49, 0
%51 = zext i1 %50 to i64
%52 = select i1 %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0)
%53 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %52)
%54 = load i32, i32* @EXIT_SUCCESS
ret i32 %54
}

LLVM IR (-O2):
@.str = [13 x i8] c"GenuineIntel\00"
@.str.1 = [13 x i8] c"AuthenticAMD\00"
@.str.2 = [27 x i8] c"HyperThreading Status: %s\0A\00"
@.str.3 = [4 x i8] c"YES\00"
@.str.4 = [3 x i8] c"NO\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x i32]
%4 = alloca [4 x i32]
%5 = bitcast [3 x i32]* %3 to i8*
%6 = bitcast [4 x i32]* %4 to i8*
%7 = tail call i32 (...) @read_rflags()
%8 = xor i32 %7, 2097152
%9 = tail call i32 @write_rflags(i32 %8)
%10 = tail call i32 (...) @read_rflags()
%11 = xor i32 %10, %7
%12 = and i32 %11, 2097152
%13 = icmp eq i32 %12, 0
br i1 %13, label %37, label %14
14: ; preds = %2
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%16 = call i32 @do_cpuid(i32 0, i32* %15)
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
store i32 %18, i32* %19
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%21 = load i32, i32* %20
%22 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 1
store i32 %21, i32* %22
%23 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%24 = load i32, i32* %23
%25 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 2
store i32 %24, i32* %25
%26 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 12)
%27 = icmp eq i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %14
%29 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %28, %14
%32 = call i32 @do_cpuid(i32 1, i32* %15)
%33 = load i32, i32* %20
%34 = and i32 %33, 268435456
%35 = icmp eq i32 %34, 0
%36 = select i1 %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0)
br label %37
37: ; preds = %28, %31, %2
%38 = phi i8* [ %36, %31 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), %28 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), %2 ]
%39 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%40 = load i32, i32* @EXIT_SUCCESS
ret i32 %40
}