#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*/ vendor_id;
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 /*<<< orphan*/ strncmp(char *, char *, int);
const char *get_hypervisor_dmi(void) {
  FILE *f = fopen("/sys/class/dmi/id/sys_vendor", "r");
  char vendor_id[128];
  if (!f)
    return NULL;
  if (fgets(vendor_id, sizeof(vendor_id), f) == NULL) {
    fclose(f);
    return NULL;
  }
  fclose(f);
  if (!strncmp(vendor_id, "VMware", 6))
    return "VMware";
  else if (!strncmp(vendor_id, "Microsoft Corporation", 21))
    return "VirtualPC";
  else if (!strncmp(vendor_id, "innotek GmbH", 12))
    return "VirtualBox";
  else if (!strncmp(vendor_id, "Parallels", 9))
    return "Parallels";
  else
    return NULL;
}


x86 assembly (clang, -O0):
<get_hypervisor_dmi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    0xeae(%rip),%rdi
lea    0xec2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117a <get_hypervisor_dmi+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    1284 <get_hypervisor_dmi+0x144>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    11af <get_hypervisor_dmi+0x6f>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    1284 <get_hypervisor_dmi+0x144>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x90(%rbp),%rdi
lea    0xe57(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11e9 <get_hypervisor_dmi+0xa9>
lea    0xe3d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1284 <get_hypervisor_dmi+0x144>
lea    -0x90(%rbp),%rdi
lea    0xe2d(%rip),%rsi
mov    $0x15,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    121a <get_hypervisor_dmi+0xda>
lea    0xe29(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1284 <get_hypervisor_dmi+0x144>
lea    -0x90(%rbp),%rdi
lea    0xe1c(%rip),%rsi
mov    $0xc,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    124b <get_hypervisor_dmi+0x10b>
lea    0xe0f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1284 <get_hypervisor_dmi+0x144>
lea    -0x90(%rbp),%rdi
lea    0xe03(%rip),%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    127c <get_hypervisor_dmi+0x13c>
lea    0xde9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1284 <get_hypervisor_dmi+0x144>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_hypervisor_dmi>:
push   %r14
push   %rbx
sub    $0x88,%rsp
lea    0xeaf(%rip),%rdi
lea    0xec3(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11f5 <get_hypervisor_dmi+0xb5>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %r14,%r14
je     11f5 <get_hypervisor_dmi+0xb5>
lea    0xe8d(%rip),%rbx
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11f7 <get_hypervisor_dmi+0xb7>
lea    0xe79(%rip),%rsi
mov    %rsp,%rdi
mov    $0x15,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1205 <get_hypervisor_dmi+0xc5>
lea    0xe81(%rip),%rsi
mov    %rsp,%rdi
mov    $0xc,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     120e <get_hypervisor_dmi+0xce>
lea    0xe81(%rip),%r14
mov    %rsp,%rdi
mov    %r14,%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
xor    %ebx,%ebx
test   %eax,%eax
cmove  %r14,%rbx
jmp    11f7 <get_hypervisor_dmi+0xb7>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe2e(%rip),%rbx
jmp    11f7 <get_hypervisor_dmi+0xb7>
lea    0xe3c(%rip),%rbx
jmp    11f7 <get_hypervisor_dmi+0xb7>

LLVM IR (-O0):
@.str = [29 x i8] c"/sys/class/dmi/id/sys_vendor\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"VMware\00"
@.str.3 = [22 x i8] c"Microsoft Corporation\00"
@.str.4 = [10 x i8] c"VirtualPC\00"
@.str.5 = [13 x i8] c"innotek GmbH\00"
@.str.6 = [11 x i8] c"VirtualBox\00"
@.str.7 = [10 x i8] c"Parallels\00"
define i8* @get_hypervisor_dmi() {
%1 = alloca i8*
%2 = alloca i32*
%3 = alloca [128 x i8]
%4 = call i32* @fopen(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %8, label %7
7: ; preds = %0
store i8* null, i8** %1
br label %39
8: ; preds = %0
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%10 = load i32*, i32** %2
%11 = call i32* @fgets(i8* %9, i32 128, i32* %10)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32*, i32** %2
%15 = call i32 @fclose(i32* %14)
store i8* null, i8** %1
br label %39
16: ; preds = %8
%17 = load i32*, i32** %2
%18 = call i32 @fclose(i32* %17)
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%20 = call i32 @strncmp(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 6)
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %16
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %1
br label %39
23: ; preds = %16
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%25 = call i32 @strncmp(i8* %24, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 21)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %23
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8** %1
br label %39
28: ; preds = %23
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%30 = call i32 @strncmp(i8* %29, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 12)
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %28
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8** %1
br label %39
33: ; preds = %28
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%35 = call i32 @strncmp(i8* %34, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i32 9)
%36 = icmp ne i32 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %33
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8** %1
br label %39
38: ; preds = %33
store i8* null, i8** %1
br label %39
39: ; preds = %38, %37, %32, %27, %22, %13, %7
%40 = load i8*, i8** %1
ret i8* %40
}

LLVM IR (-O2):
@.str = [29 x i8] c"/sys/class/dmi/id/sys_vendor\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"VMware\00"
@.str.3 = [22 x i8] c"Microsoft Corporation\00"
@.str.4 = [10 x i8] c"VirtualPC\00"
@.str.5 = [13 x i8] c"innotek GmbH\00"
@.str.6 = [11 x i8] c"VirtualBox\00"
@.str.7 = [10 x i8] c"Parallels\00"
define i8* @get_hypervisor_dmi() {
%1 = alloca [128 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%4 = icmp eq i32* %2, null
br i1 %4, label %22, label %5
5: ; preds = %0
%6 = call i32* @fgets(i8* %3, i32 128, i32* %2)
%7 = icmp eq i32* %6, null
%8 = call i32 @fclose(i32* %2)
br i1 %7, label %22, label %9
9: ; preds = %5
%10 = call i32 @strncmp(i8* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 6)
%11 = icmp eq i32 %10, 0
br i1 %11, label %22, label %12
12: ; preds = %9
%13 = call i32 @strncmp(i8* %3, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 21)
%14 = icmp eq i32 %13, 0
br i1 %14, label %22, label %15
15: ; preds = %12
%16 = call i32 @strncmp(i8* %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 12)
%17 = icmp eq i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = call i32 @strncmp(i8* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i32 9)
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* null
br label %22
22: ; preds = %5, %18, %15, %12, %9, %0
%23 = phi i8* [ null, %0 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %9 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), %12 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), %15 ], [ %21, %18 ], [ null, %5 ]
ret i8* %23
}