#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ cpuid(int, int *, int *, int *, int *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int check_for_xen(int pv_context) {
  uint32_t eax, ebx, ecx, edx;
  char signature[13];
  uint32_t base;
  for (base = 0x40000000; base < 0x40010000; base += 0x100) {
    cpuid(base, &eax, &ebx, &ecx, &edx, pv_context);
    *(uint32_t *)(signature + 0) = ebx;
    *(uint32_t *)(signature + 4) = ecx;
    *(uint32_t *)(signature + 8) = edx;
    signature[12] = '\0';
    if (!strcmp("XenVMMXenVMM", signature) && (eax >= (base + 2)))
      goto found;
  }
  return 0;
found:
  cpuid(base + 1, &eax, &ebx, &ecx, &edx, pv_context);
  return eax;
}


x86 assembly (clang, -O0):
<check_for_xen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x40000000,-0x2c(%rbp)
cmpl   $0x40010000,-0x2c(%rbp)
jge    11b5 <check_for_xen+0x95>
mov    -0x2c(%rbp),%edi
mov    -0x8(%rbp),%r9d
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
lea    -0x18(%rbp),%r8
call   1040 <cpuid@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x25(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x21(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1d(%rbp)
movb   $0x0,-0x19(%rbp)
lea    -0x25(%rbp),%rsi
lea    0xe84(%rip),%rdi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11a0 <check_for_xen+0x80>
mov    -0xc(%rbp),%eax
mov    -0x2c(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jl     11a0 <check_for_xen+0x80>
jmp    11c1 <check_for_xen+0xa1>
jmp    11a5 <check_for_xen+0x85>
mov    -0x2c(%rbp),%eax
add    $0x100,%eax
mov    %eax,-0x2c(%rbp)
jmp    1132 <check_for_xen+0x12>
movl   $0x0,-0x4(%rbp)
jmp    11e6 <check_for_xen+0xc6>
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
mov    -0x8(%rbp),%r9d
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
lea    -0x18(%rbp),%r8
call   1040 <cpuid@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_for_xen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebp
mov    $0x40000002,%ebx
lea    0xc(%rsp),%r13
movabs $0x65584d4d566e6558,%r15
4d 58 65
movabs $0x4d4d566e65584d,%r12
jmp    1153 <check_for_xen+0x43>
add    $0x100,%ebx
cmp    $0x4000ff00,%r14d
jae    11d3 <check_for_xen+0xc3>
lea    -0x2(%rbx),%r14d
mov    %r14d,%edi
lea    0x8(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %r13,%r8
mov    %ebp,%r9d
call   1030 <cpuid@plt>
mov    0x14(%rsp),%eax
mov    %eax,0x18(%rsp)
mov    0x10(%rsp),%eax
mov    %eax,0x1c(%rsp)
mov    0xc(%rsp),%eax
mov    %eax,0x20(%rsp)
movb   $0x0,0x24(%rsp)
mov    0x18(%rsp),%rax
xor    %r15,%rax
mov    0x1d(%rsp),%rcx
xor    %r12,%rcx
or     %rax,%rcx
jne    1140 <check_for_xen+0x30>
cmp    %ebx,0x8(%rsp)
jl     1140 <check_for_xen+0x30>
add    $0xffffffff,%ebx
lea    0x8(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %ebx,%edi
mov    %ebp,%r9d
call   1030 <cpuid@plt>
mov    0x8(%rsp),%eax
jmp    11d5 <check_for_xen+0xc5>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"XenVMMXenVMM\00"
define i32 @check_for_xen(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [13 x i8]
%9 = alloca i32
store i32 %0, i32* %3
store i32 1073741824, i32* %9
br label %10
10: ; preds = %40, %1
%11 = load i32, i32* %9
%12 = icmp slt i32 %11, 1073807360
br i1 %12, label %13, label %43
13: ; preds = %10
%14 = load i32, i32* %9
%15 = load i32, i32* %3
%16 = call i32 @cpuid(i32 %14, i32* %4, i32* %5, i32* %6, i32* %7, i32 %15)
%17 = load i32, i32* %5
%18 = getelementptr inbounds [13 x i8], [13 x i8]* %8, i64 0, i64 0
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = bitcast i8* %19 to i32*
store i32 %17, i32* %20
%21 = load i32, i32* %6
%22 = getelementptr inbounds [13 x i8], [13 x i8]* %8, i64 0, i64 0
%23 = getelementptr inbounds i8, i8* %22, i64 4
%24 = bitcast i8* %23 to i32*
store i32 %21, i32* %24
%25 = load i32, i32* %7
%26 = getelementptr inbounds [13 x i8], [13 x i8]* %8, i64 0, i64 0
%27 = getelementptr inbounds i8, i8* %26, i64 8
%28 = bitcast i8* %27 to i32*
store i32 %25, i32* %28
%29 = getelementptr inbounds [13 x i8], [13 x i8]* %8, i64 0, i64 12
store i8 0, i8* %29
%30 = getelementptr inbounds [13 x i8], [13 x i8]* %8, i64 0, i64 0
%31 = call i32 @strcmp(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %39, label %33
33: ; preds = %13
%34 = load i32, i32* %4
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 2
%37 = icmp sge i32 %34, %36
br i1 %37, label %38, label %39
38: ; preds = %33
br label %44
39: ; preds = %33, %13
br label %40
40: ; preds = %39
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 256
store i32 %42, i32* %9
br label %10
43: ; preds = %10
store i32 0, i32* %2
br label %50
44: ; preds = %38
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
%47 = load i32, i32* %3
%48 = call i32 @cpuid(i32 %46, i32* %4, i32* %5, i32* %6, i32* %7, i32 %47)
%49 = load i32, i32* %4
store i32 %49, i32* %2
br label %50
50: ; preds = %44, %43
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
@.str = [13 x i8] c"XenVMMXenVMM\00"
define i32 @check_for_xen(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [13 x i8]
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%12 = bitcast [13 x i8]* %6 to i32*
%13 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 4
%14 = bitcast i8* %13 to i32*
%15 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 8
%16 = bitcast i8* %15 to i32*
%17 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 12
br label %18
18: ; preds = %1, %30
%19 = phi i32 [ 1073741824, %1 ], [ %31, %30 ]
%20 = call i32 @cpuid(i32 %19, i32* %2, i32* %3, i32* %4, i32* %5, i32 %0)
%21 = load i32, i32* %3
store i32 %21, i32* %12
%22 = load i32, i32* %4
store i32 %22, i32* %14
%23 = load i32, i32* %5
store i32 %23, i32* %16
store i8 0, i8* %17
%24 = call i32 @bcmp(i8* dereferenceable(13) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* dereferenceable(13) %11, i64 13)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %18
%27 = load i32, i32* %2
%28 = or i32 %19, 2
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %18, %26
%31 = add nuw nsw i32 %19, 256
%32 = icmp ult i32 %19, 1073807104
br i1 %32, label %18, label %37
33: ; preds = %26
%34 = or i32 %19, 1
%35 = call i32 @cpuid(i32 %34, i32* %2, i32* %3, i32* %4, i32* %5, i32 %0)
%36 = load i32, i32* %2
br label %37
37: ; preds = %30, %33
%38 = phi i32 [ %36, %33 ], [ 0, %30 ]
ret i32 %38
}