#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(0x80000000, regs);
      if (regs[0] >= 0x80000001) {
        do_cpuid(0x80000001, regs);
        has_feature = (regs[3] & 0x20000000);
      }
    }
  }
  printf("x86_64 support: %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     1248 <main+0xf8>
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    1243 <main+0xf3>
lea    -0x40(%rbp),%rsi
mov    $0x80000000,%edi
call   1070 <do_cpuid@plt>
cmpl   $0x80000001,-0x40(%rbp)
jb     123e <main+0xee>
lea    -0x40(%rbp),%rsi
mov    $0x80000001,%edi
call   1070 <do_cpuid@plt>
mov    -0x34(%rbp),%eax
and    $0x20000000,%eax
mov    %eax,-0x14(%rbp)
jmp    1243 <main+0xf3>
jmp    1248 <main+0xf8>
mov    -0x14(%rbp),%ecx
lea    0xde0(%rip),%rsi
lea    0xdd5(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xdb3(%rip),%rdi
call   1060 <printf@plt>
mov    0x2d6d(%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    0xeb7(%rip),%rbx
test   $0x200000,%eax
je     1216 <main+0xc6>
mov    %rsp,%rsi
xor    %edi,%edi
call   1070 <do_cpuid@plt>
mov    0x4(%rsp),%eax
mov    %eax,0x14(%rsp)
mov    0x8(%rsp),%rax
rol    $0x20,%rax
mov    %rax,0x18(%rsp)
lea    0xe53(%rip),%rsi
lea    0x14(%rsp),%rdi
mov    $0xc,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
je     11dc <main+0x8c>
lea    0xe45(%rip),%rsi
lea    0x14(%rsp),%rdi
mov    $0xc,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
jne    1216 <main+0xc6>
mov    %rsp,%rsi
mov    $0x80000000,%edi
call   1070 <do_cpuid@plt>
cmpl   $0x80000001,(%rsp)
jb     1216 <main+0xc6>
mov    %rsp,%rsi
mov    $0x80000001,%edi
call   1070 <do_cpuid@plt>
testb  $0x20,0xf(%rsp)
lea    0xe27(%rip),%rax
lea    0xe1c(%rip),%rbx
cmove  %rax,%rbx
lea    0xdfd(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    0x2db4(%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 = [20 x i8] c"x86_64 support: %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 %55
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 %54
41: ; preds = %37, %20
%42 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%43 = call i32 @do_cpuid(i32 -2147483648, i32* %42)
%44 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%45 = load i32, i32* %44
%46 = icmp uge i32 %45, -2147483647
br i1 %46, label %47, label %53
47: ; preds = %41
%48 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%49 = call i32 @do_cpuid(i32 -2147483647, i32* %48)
%50 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 3
%51 = load i32, i32* %50
%52 = and i32 %51, 536870912
store i32 %52, i32* %6
br label %53
53: ; preds = %47, %41
br label %54
54: ; preds = %53, %37
br label %55
55: ; preds = %54, %2
%56 = load i32, i32* %6
%57 = icmp ne i32 %56, 0
%58 = zext i1 %57 to i64
%59 = select i1 %57, 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)
%60 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %59)
%61 = load i32, i32* @EXIT_SUCCESS
ret i32 %61
}

LLVM IR (-O2):
@.str = [13 x i8] c"GenuineIntel\00"
@.str.1 = [13 x i8] c"AuthenticAMD\00"
@.str.2 = [20 x i8] c"x86_64 support: %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 %41, 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 %41
31: ; preds = %28, %14
%32 = call i32 @do_cpuid(i32 -2147483648, i32* %15)
%33 = load i32, i32* %15
%34 = icmp ugt i32 %33, -2147483648
br i1 %34, label %35, label %41
35: ; preds = %31
%36 = call i32 @do_cpuid(i32 -2147483647, i32* %15)
%37 = load i32, i32* %20
%38 = and i32 %37, 536870912
%39 = icmp eq i32 %38, 0
%40 = select i1 %39, 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 %41
41: ; preds = %28, %35, %31, %2
%42 = phi i8* [ %40, %35 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), %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 ]
%43 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @EXIT_SUCCESS
ret i32 %44
}