#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 /*<<< orphan*/ hyper_vendor_id;

/* Variables and functions */
int /*<<< orphan*/ cpuid(int, unsigned int *, unsigned int *, unsigned int *,
                         unsigned int *);
int /*<<< orphan*/ memcpy(char *, unsigned int *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strncmp(char *, char *, int);
const char *get_hypervisor_cpuid(void) {
  unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0;
  char hyper_vendor_id[13];
  memset(hyper_vendor_id, 0, sizeof(hyper_vendor_id));
  cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
  memcpy(hyper_vendor_id + 0, &ebx, 4);
  memcpy(hyper_vendor_id + 4, &ecx, 4);
  memcpy(hyper_vendor_id + 8, &edx, 4);
  hyper_vendor_id[12] = '\0';
  if (!hyper_vendor_id[0])
    return NULL;
  else if (!strncmp("XenVMMXenVMM", hyper_vendor_id, 12))
    return "Xen hvm";
  else if (!strncmp("KVMKVMKVM", hyper_vendor_id, 9))
    return "KVM";
  else if (!strncmp("Microsoft Hv", hyper_vendor_id, 12))
    return "Microsoft HyperV";
  else if (!strncmp("VMwareVMware", hyper_vendor_id, 12))
    return "VMware";
  else
    return NULL;
}


x86 assembly (clang, -O0):
<get_hypervisor_cpuid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x25(%rbp),%rdi
xor    %esi,%esi
mov    $0xd,%edx
call   1040 <memset@plt>
mov    $0x40000000,%edi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
lea    -0x18(%rbp),%r8
call   1060 <cpuid@plt>
lea    -0x25(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
lea    -0x25(%rbp),%rdi
add    $0x4,%rdi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
lea    -0x25(%rbp),%rdi
add    $0x8,%rdi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
movb   $0x0,-0x19(%rbp)
cmpb   $0x0,-0x25(%rbp)
jne    11e7 <get_hypervisor_cpuid+0xa7>
movq   $0x0,-0x8(%rbp)
jmp    12a7 <get_hypervisor_cpuid+0x167>
lea    -0x25(%rbp),%rsi
lea    0xe0e(%rip),%rdi
mov    $0xc,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1215 <get_hypervisor_cpuid+0xd5>
lea    0xe01(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12a7 <get_hypervisor_cpuid+0x167>
lea    -0x25(%rbp),%rsi
lea    0xdf5(%rip),%rdi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1243 <get_hypervisor_cpuid+0x103>
lea    0xde1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12a7 <get_hypervisor_cpuid+0x167>
lea    -0x25(%rbp),%rsi
lea    0xdd1(%rip),%rdi
mov    $0xc,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1271 <get_hypervisor_cpuid+0x131>
lea    0xdc4(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12a7 <get_hypervisor_cpuid+0x167>
lea    -0x25(%rbp),%rsi
lea    0xdc1(%rip),%rdi
mov    $0xc,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    129f <get_hypervisor_cpuid+0x15f>
lea    0xdad(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12a7 <get_hypervisor_cpuid+0x167>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_hypervisor_cpuid>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
movl   $0x0,0x1c(%rsp)
movl   $0x0,0x18(%rsp)
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
lea    0x3(%rsp),%r14
xor    %r15d,%r15d
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xd,%edx
call   1040 <memset@plt>
lea    0x1c(%rsp),%rsi
lea    0x18(%rsp),%rbx
lea    0x14(%rsp),%r12
lea    0x10(%rsp),%r13
mov    $0x40000000,%edi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1060 <cpuid@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
lea    0x7(%rsp),%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
lea    0xb(%rsp),%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
movb   $0x0,0xf(%rsp)
cmpb   $0x0,0x3(%rsp)
je     127e <get_hypervisor_cpuid+0x13e>
lea    0xe0a(%rip),%rdi
lea    0x3(%rsp),%rsi
mov    $0xc,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1265 <get_hypervisor_cpuid+0x125>
lea    0xe05(%rip),%rdi
lea    0x3(%rsp),%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     126e <get_hypervisor_cpuid+0x12e>
lea    0xdf5(%rip),%rdi
lea    0x3(%rsp),%rsi
mov    $0xc,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1277 <get_hypervisor_cpuid+0x137>
lea    0xdf9(%rip),%rdi
lea    0x3(%rsp),%rsi
mov    $0xc,%edx
call   1030 <strncmp@plt>
xor    %r15d,%r15d
test   %eax,%eax
lea    0xde4(%rip),%rax
cmove  %rax,%r15
jmp    127e <get_hypervisor_cpuid+0x13e>
lea    0xda1(%rip),%r15
jmp    127e <get_hypervisor_cpuid+0x13e>
lea    0xda6(%rip),%r15
jmp    127e <get_hypervisor_cpuid+0x13e>
lea    0xdae(%rip),%r15
mov    %r15,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"XenVMMXenVMM\00"
@.str.1 = [8 x i8] c"Xen hvm\00"
@.str.2 = [10 x i8] c"KVMKVMKVM\00"
@.str.3 = [4 x i8] c"KVM\00"
@.str.4 = [13 x i8] c"Microsoft Hv\00"
@.str.5 = [17 x i8] c"Microsoft HyperV\00"
@.str.6 = [13 x i8] c"VMwareVMware\00"
@.str.7 = [7 x i8] c"VMware\00"
define i8* @get_hypervisor_cpuid() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [13 x i8]
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%7 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 13)
%9 = call i32 @cpuid(i32 1073741824, i32* %2, i32* %3, i32* %4, i32* %5)
%10 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = call i32 @memcpy(i8* %11, i32* %3, i32 4)
%13 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%14 = getelementptr inbounds i8, i8* %13, i64 4
%15 = call i32 @memcpy(i8* %14, i32* %4, i32 4)
%16 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%17 = getelementptr inbounds i8, i8* %16, i64 8
%18 = call i32 @memcpy(i8* %17, i32* %5, i32 4)
%19 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 12
store i8 0, i8* %19
%20 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%21 = load i8, i8* %20
%22 = icmp ne i8 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %0
store i8* null, i8** %1
br label %45
24: ; preds = %0
%25 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%26 = call i32 @strncmp(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %25, i32 12)
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %24
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %1
br label %45
29: ; preds = %24
%30 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%31 = call i32 @strncmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %30, i32 9)
%32 = icmp ne i32 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %29
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %1
br label %45
34: ; preds = %29
%35 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%36 = call i32 @strncmp(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %35, i32 12)
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %34
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8** %1
br label %45
39: ; preds = %34
%40 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%41 = call i32 @strncmp(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %40, i32 12)
%42 = icmp ne i32 %41, 0
br i1 %42, label %44, label %43
43: ; preds = %39
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8** %1
br label %45
44: ; preds = %39
store i8* null, i8** %1
br label %45
45: ; preds = %44, %43, %38, %33, %28, %23
%46 = load i8*, i8** %1
ret i8* %46
}

LLVM IR (-O2):
@.str = [13 x i8] c"XenVMMXenVMM\00"
@.str.1 = [8 x i8] c"Xen hvm\00"
@.str.2 = [10 x i8] c"KVMKVMKVM\00"
@.str.3 = [4 x i8] c"KVM\00"
@.str.4 = [13 x i8] c"Microsoft Hv\00"
@.str.5 = [17 x i8] c"Microsoft HyperV\00"
@.str.6 = [13 x i8] c"VMwareVMware\00"
@.str.7 = [7 x i8] c"VMware\00"
define i8* @get_hypervisor_cpuid() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [13 x i8]
%6 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%7 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%8 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%9 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%10 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i32 0, i32 13)
%12 = call i32 @cpuid(i32 1073741824, i32* %1, i32* %2, i32* %3, i32* %4)
%13 = call i32 @memcpy(i8* %10, i32* %2, i32 4)
%14 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 4
%15 = call i32 @memcpy(i8* %14, i32* %3, i32 4)
%16 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 8
%17 = call i32 @memcpy(i8* %16, i32* %4, i32 4)
%18 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 12
store i8 0, i8* %18
%19 = load i8, i8* %10
%20 = icmp eq i8 %19, 0
br i1 %20, label %34, label %21
21: ; preds = %0
%22 = call i32 @strncmp(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %10, i32 12)
%23 = icmp eq i32 %22, 0
br i1 %23, label %34, label %24
24: ; preds = %21
%25 = call i32 @strncmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %10, i32 9)
%26 = icmp eq i32 %25, 0
br i1 %26, label %34, label %27
27: ; preds = %24
%28 = call i32 @strncmp(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %10, i32 12)
%29 = icmp eq i32 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %27
%31 = call i32 @strncmp(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %10, i32 12)
%32 = icmp eq i32 %31, 0
%33 = select i1 %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* null
br label %34
34: ; preds = %30, %27, %24, %21, %0
%35 = phi i8* [ null, %0 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %21 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %24 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), %27 ], [ %33, %30 ]
ret i8* %35
}