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

/* Variables and functions */
int /*<<< orphan*/ get_cpuid(int, unsigned int *);
int /*<<< orphan*/ memcpy(char *, unsigned int *, int);
int /*<<< orphan*/ memset(unsigned int *, int /*<<< orphan*/, int);
int get_hypervisor_id(char *id) {
  unsigned regs[] = {0, 0, 0, 0};
  id[0] = 0;
  get_cpuid(1, regs);
  if (regs[2] & (1 << 31)) {
    memset(regs, 0, sizeof(regs));
    get_cpuid(0x40000000, regs);
    memcpy(id, &regs[1], 12);
    id[12] = 0;
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_hypervisor_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x20(%rbp),%rsi
mov    $0x1,%edi
call   1030 <get_cpuid@plt>
mov    -0x18(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     11ba <get_hypervisor_id+0x8a>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
lea    -0x20(%rbp),%rsi
mov    $0x40000000,%edi
call   1030 <get_cpuid@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
add    $0x4,%rsi
mov    $0xc,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,0xc(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11c1 <get_hypervisor_id+0x91>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_hypervisor_id>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,(%rdi)
mov    %rsp,%rsi
mov    $0x1,%edi
call   1030 <get_cpuid@plt>
xor    %eax,%eax
cmpl   $0x0,0x8(%rsp)
jns    1194 <get_hypervisor_id+0x64>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    $0x40000000,%edi
mov    %r14,%rsi
call   1030 <get_cpuid@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xc,%edx
call   1050 <memcpy@plt>
movb   $0x0,0xc(%rbx)
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @get_hypervisor_id(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [4 x i32]
store i8* %0, i8** %3
%5 = bitcast [4 x i32]* %4 to i8*
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
store i8 0, i8* %7
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%9 = call i32 @get_cpuid(i32 1, i32* %8)
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%11 = load i32, i32* %10
%12 = and i32 %11, -2147483648
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %1
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%16 = call i32 @memset(i32* %15, i32 0, i32 16)
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%18 = call i32 @get_cpuid(i32 1073741824, i32* %17)
%19 = load i8*, i8** %3
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%21 = call i32 @memcpy(i8* %19, i32* %20, i32 12)
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 12
store i8 0, i8* %23
store i32 1, i32* %2
br label %25
24: ; preds = %1
store i32 0, i32* %2
br label %25
25: ; preds = %24, %14
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
define i32 @get_hypervisor_id(i8* %0) {
%2 = alloca [4 x i32]
%3 = bitcast [4 x i32]* %2 to i8*
store i8 0, i8* %0
%4 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%5 = call i32 @get_cpuid(i32 1, i32* %4)
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%7 = load i32, i32* %6
%8 = icmp sgt i32 %7, -1
br i1 %8, label %15, label %9
9: ; preds = %1
%10 = call i32 @memset(i32* %4, i32 0, i32 16)
%11 = call i32 @get_cpuid(i32 1073741824, i32* %4)
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%13 = call i32 @memcpy(i8* %0, i32* %12, i32 12)
%14 = getelementptr inbounds i8, i8* %0, i64 12
store i8 0, i8* %14
br label %15
15: ; preds = %1, %9
%16 = phi i32 [ 1, %9 ], [ 0, %1 ]
ret i32 %16
}