#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *);
char *get_hypervisor_cpuid();
char *get_hypervisor_dmi();
scalar_t__ has_pci_device(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int main(int argc, char **argv) {
  FILE *f;
  const char *hvm;
  char buf[256];
  if ((hvm = get_hypervisor_cpuid()) != NULL ||
      (hvm = get_hypervisor_dmi()) != NULL)
    printf("%s\n", hvm);
  else if ((f = fopen("/proc/xen"
                      "/capabilities",
                      "r")) != NULL) {
    int dom0 = 0;
    if (fscanf(f, "%s", buf) == 1 && !strcmp(buf, "control_d"))
      dom0 = 1;
    printf("Xen %s\n", dom0 ? "dom0" : "domU");
    fclose(f);
  } else if ((f = fopen("/sys/hypervisor/type", "r")) != NULL) {
    if (fgets(buf, sizeof(buf), f) != NULL && !strncmp(buf, "xen", 3))
      printf("Xen\n");
    fclose(f);
  } else if (has_pci_device(0x5853, 0x0001)) {
    printf("Xen full\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <get_hypervisor_cpuid@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11e3 <main+0x43>
mov    $0x0,%al
call   10a0 <get_hypervisor_dmi@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11fa <main+0x5a>
mov    -0x20(%rbp),%rsi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1355 <main+0x1b5>
lea    0xdff(%rip),%rdi
lea    0xe0f(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12a2 <main+0x102>
movl   $0x0,-0x124(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    0xde2(%rip),%rsi
call   1060 <fscanf@plt>
cmp    $0x1,%eax
jne    126b <main+0xcb>
lea    -0x120(%rbp),%rdi
lea    0xdc9(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    126b <main+0xcb>
movl   $0x1,-0x124(%rbp)
mov    -0x124(%rbp),%ecx
lea    0xdbb(%rip),%rsi
lea    0xdaf(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1350 <main+0x1b0>
lea    0xd8f(%rip),%rdi
lea    0xd67(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     131f <main+0x17f>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1311 <main+0x171>
lea    -0x120(%rbp),%rdi
lea    0xd5d(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1311 <main+0x171>
lea    0xd47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
jmp    134b <main+0x1ab>
mov    $0x5853,%edi
mov    $0x1,%esi
call   10b0 <has_pci_device@plt>
cmp    $0x0,%rax
je     1346 <main+0x1a6>
lea    0xd17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    134b <main+0x1ab>
jmp    1350 <main+0x1b0>
jmp    1355 <main+0x1b5>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x100,%rsp
xor    %eax,%eax
call   1090 <get_hypervisor_cpuid@plt>
test   %rax,%rax
jne    11c0 <main+0x20>
xor    %eax,%eax
call   10a0 <get_hypervisor_dmi@plt>
test   %rax,%rax
je     11d3 <main+0x33>
mov    %rax,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
ret
lea    0xe26(%rip),%rdi
lea    0xe36(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1237 <main+0x97>
mov    %rax,%rbx
lea    0xe24(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1070 <fscanf@plt>
cmp    $0x1,%eax
jne    128d <main+0xed>
movabs $0x5f6c6f72746e6f63,%rax
6f 6c 5f
xor    (%rsp),%rax
movzwl 0x8(%rsp),%ecx
xor    $0x64,%rcx
or     %rax,%rcx
lea    0xe04(%rip),%rax
lea    0xe02(%rip),%rsi
cmove  %rax,%rsi
jmp    1294 <main+0xf4>
lea    0xdfa(%rip),%rdi
lea    0xdd2(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12af <main+0x10f>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12a2 <main+0x102>
lea    0xddf(%rip),%rsi
mov    %rsp,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    12a2 <main+0x102>
lea    0xdd4(%rip),%rdi
call   1040 <puts@plt>
jmp    12a2 <main+0x102>
lea    0xd9f(%rip),%rsi
lea    0xd8b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    11c8 <main+0x28>
mov    $0x5853,%edi
mov    $0x1,%esi
call   10b0 <has_pci_device@plt>
test   %rax,%rax
je     11c8 <main+0x28>
lea    0xd83(%rip),%rdi
jmp    11c3 <main+0x23>

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [23 x i8] c"/proc/xen/capabilities\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [10 x i8] c"control_d\00"
@.str.5 = [8 x i8] c"Xen %s\0A\00"
@.str.6 = [5 x i8] c"dom0\00"
@.str.7 = [5 x i8] c"domU\00"
@.str.8 = [21 x i8] c"/sys/hypervisor/type\00"
@.str.9 = [4 x i8] c"xen\00"
@.str.10 = [5 x i8] c"Xen\0A\00"
@.str.11 = [10 x i8] c"Xen full\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca [256 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i8* (...) @get_hypervisor_cpuid()
store i8* %10, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = call i8* (...) @get_hypervisor_dmi()
store i8* %13, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12, %2
%16 = load i8*, i8** %7
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %64
18: ; preds = %12
%19 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %19, i32** %6
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %39
21: ; preds = %18
store i32 0, i32* %9
%22 = load i32*, i32** %6
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%24 = call i32 @fscanf(i32* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%28 = call i32 @strcmp(i8* %27, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %26
store i32 1, i32* %9
br label %31
31: ; preds = %30, %26, %21
%32 = load i32, i32* %9
%33 = icmp ne i32 %32, 0
%34 = zext i1 %33 to i64
%35 = select i1 %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %35)
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
br label %63
39: ; preds = %18
%40 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %40, i32** %6
%41 = icmp ne i32* %40, null
br i1 %41, label %42, label %56
42: ; preds = %39
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%44 = load i32*, i32** %6
%45 = call i32* @fgets(i8* %43, i32 256, i32* %44)
%46 = icmp ne i32* %45, null
br i1 %46, label %47, label %53
47: ; preds = %42
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%49 = call i32 @strncmp(i8* %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 3)
%50 = icmp ne i32 %49, 0
br i1 %50, label %53, label %51
51: ; preds = %47
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
br label %53
53: ; preds = %51, %47, %42
%54 = load i32*, i32** %6
%55 = call i32 @fclose(i32* %54)
br label %62
56: ; preds = %39
%57 = call i64 @has_pci_device(i32 22611, i32 1)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
br label %61
61: ; preds = %59, %56
br label %62
62: ; preds = %61, %53
br label %63
63: ; preds = %62, %31
br label %64
64: ; preds = %63, %15
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [23 x i8] c"/proc/xen/capabilities\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [10 x i8] c"control_d\00"
@.str.5 = [8 x i8] c"Xen %s\0A\00"
@.str.6 = [5 x i8] c"dom0\00"
@.str.7 = [5 x i8] c"domU\00"
@.str.8 = [21 x i8] c"/sys/hypervisor/type\00"
@.str.9 = [4 x i8] c"xen\00"
@str = [9 x i8] c"Xen full\00"
@str.12 = [4 x i8] c"Xen\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i8* (...) @get_hypervisor_cpuid()
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i8* (...) @get_hypervisor_dmi()
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %7, %2
%11 = phi i8* [ %5, %2 ], [ %8, %7 ]
%12 = tail call i32 @puts(i8* dereferenceable(1) %11)
br label %45
13: ; preds = %7
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %27, label %16
16: ; preds = %13
%17 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = call i32 @bcmp(i8* dereferenceable(10) %4, i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i64 10)
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0)
br label %23
23: ; preds = %19, %16
%24 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), %16 ], [ %22, %19 ]
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %24)
%26 = call i32 @fclose(i32* %14)
br label %45
27: ; preds = %13
%28 = tail call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i32* %28, null
br i1 %29, label %40, label %30
30: ; preds = %27
%31 = call i32* @fgets(i8* %4, i32 256, i32* %28)
%32 = icmp eq i32* %31, null
br i1 %32, label %38, label %33
33: ; preds = %30
%34 = call i32 @strncmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 3)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.12, i64 0, i64 0))
br label %38
38: ; preds = %36, %33, %30
%39 = call i32 @fclose(i32* %28)
br label %45
40: ; preds = %27
%41 = tail call i64 @has_pci_device(i32 22611, i32 1)
%42 = icmp eq i64 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %40
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %45
45: ; preds = %23, %40, %43, %38, %10
ret i32 0
}