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

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ W_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
scalar_t__ geteuid();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ system(char *);
void Test_Or_Make_MSR_DEVICE_FILES() {
  if (access("/dev/cpu/0/msr", F_OK) == 0) {
    printf("i7z DEBUG: msr device files exist /dev/cpu/*/msr\n");
    if (access("/dev/cpu/0/msr", W_OK) == 0) {
      printf("i7z DEBUG: You have write permissions to msr device files\n");
    } else {
      printf(
          "i7z DEBUG: You DO NOT have write permissions to msr device files\n");
      printf("i7z DEBUG: A solution is to run this program as root\n");
      exit(1);
    }
  } else {
    printf("i7z DEBUG: msr device files DO NOT exist, trying out a makedev "
           "script\n");
    if (geteuid() == 0) {
      system("msr_major=202; 						"
             "	cpuid_major=203; 					"
             "		n=0; 						"
             "	while [ $n -lt 16 ]; do 				"
             "				mkdir -m 0755 -p /dev/cpu/$n; 	"
             "							mknod "
             "/dev/cpu/$n/msr -m 0600 c $msr_major $n; 			"
             "					mknod /dev/cpu/$n/cpuid -m "
             "0444 c $cpuid_major $n; 					"
             "			n=`expr $n + 1`; 			"
             "				done; 				"
             "			");
      printf("i7z DEBUG: modprobbing for msr\n");
      system("modprobe msr");
    } else {
      printf("i7z DEBUG: You DO NOT have root privileges, mknod to create "
             "device entries won't work out\n");
      printf("i7z DEBUG: A solution is to run this program as root\n");
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<Test_Or_Make_MSR_DEVICE_FILES>:
push   %rbp
mov    %rsp,%rbp
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
lea    0xe9c(%rip),%rdi
call   1060 <access@plt>
cmp    $0x0,%rax
jne    11d6 <Test_Or_Make_MSR_DEVICE_FILES+0x86>
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
call   1060 <access@plt>
cmp    $0x0,%rax
jne    11af <Test_Or_Make_MSR_DEVICE_FILES+0x5f>
lea    0xe9c(%rip),%rdi
call   1040 <printf@plt>
jmp    11d1 <Test_Or_Make_MSR_DEVICE_FILES+0x81>
lea    0xec6(%rip),%rdi
call   1040 <printf@plt>
lea    0xefc(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1243 <Test_Or_Make_MSR_DEVICE_FILES+0xf3>
lea    0xf17(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <geteuid@plt>
cmp    $0x0,%rax
jne    121c <Test_Or_Make_MSR_DEVICE_FILES+0xcc>
lea    0xf41(%rip),%rdi
call   1030 <system@plt>
lea    0x104d(%rip),%rdi
call   1040 <printf@plt>
lea    0x1061(%rip),%rdi
call   1030 <system@plt>
jmp    123e <Test_Or_Make_MSR_DEVICE_FILES+0xee>
lea    0x105d(%rip),%rdi
call   1040 <printf@plt>
lea    0xe8f(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1243 <Test_Or_Make_MSR_DEVICE_FILES+0xf3>
pop    %rbp
ret

x86 assembly (clang, -O2):
<Test_Or_Make_MSR_DEVICE_FILES>:
push   %rax
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1060 <access@plt>
test   %rax,%rax
je     11a8 <Test_Or_Make_MSR_DEVICE_FILES+0x58>
lea    0xfc2(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <geteuid@plt>
test   %rax,%rax
jne    11db <Test_Or_Make_MSR_DEVICE_FILES+0x8b>
lea    0xe85(%rip),%rdi
call   1040 <system@plt>
lea    0x103e(%rip),%rdi
call   1030 <puts@plt>
lea    0xf85(%rip),%rdi
pop    %rax
jmp    1040 <system@plt>
lea    0x1044(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
lea    0xe3c(%rip),%rdi
call   1060 <access@plt>
test   %rax,%rax
jne    11e4 <Test_Or_Make_MSR_DEVICE_FILES+0x94>
lea    0x10c5(%rip),%rdi
pop    %rax
jmp    1030 <puts@plt>
lea    0xf98(%rip),%rdi
jmp    11eb <Test_Or_Make_MSR_DEVICE_FILES+0x9b>
lea    0x1039(%rip),%rdi
call   1030 <puts@plt>
lea    0x106e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"/dev/cpu/0/msr\00"
@F_OK = global i32 0
@.str.1 = [50 x i8] c"i7z DEBUG: msr device files exist /dev/cpu/*/msr\0A\00"
@W_OK = global i32 0
@.str.2 = [59 x i8] c"i7z DEBUG: You have write permissions to msr device files\0A\00"
@.str.3 = [66 x i8] c"i7z DEBUG: You DO NOT have write permissions to msr device files\0A\00"
@.str.4 = [54 x i8] c"i7z DEBUG: A solution is to run this program as root\0A\00"
@.str.5 = [71 x i8] c"i7z DEBUG: msr device files DO NOT exist, trying out a makedev script\0A\00"
@.str.6 = [280 x i8] c"msr_major=202; \09\09\09\09\09\09\09cpuid_major=203; \09\09\09\09\09\09\09n=0; \09\09\09\09\09\09\09while [ $n -lt 16 ]; do \09\09\09\09\09\09\09\09mkdir -m 0755 -p /dev/cpu/$n; \09\09\09\09\09\09\09\09mknod /dev/cpu/$n/msr -m 0600 c $msr_major $n; \09\09\09\09\09\09\09\09mknod /dev/cpu/$n/cpuid -m 0444 c $cpuid_major $n; \09\09\09\09\09\09\09\09n=`expr $n + 1`; \09\09\09\09\09\09\09done; \09\09\09\09\09\09\09\00"
@.str.7 = [32 x i8] c"i7z DEBUG: modprobbing for msr\0A\00"
@.str.8 = [13 x i8] c"modprobe msr\00"
@.str.9 = [91 x i8] c"i7z DEBUG: You DO NOT have root privileges, mknod to create device entries won't work out\0A\00"
define void @Test_Or_Make_MSR_DEVICE_FILES() {
%1 = load i32, i32* @F_OK
%2 = call i64 @access(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %16
4: ; preds = %0
%5 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @W_OK
%7 = call i64 @access(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0))
br label %15
11: ; preds = %4
%12 = call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %9
br label %29
16: ; preds = %0
%17 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.5, i64 0, i64 0))
%18 = call i64 (...) @geteuid()
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = call i32 @system(i8* getelementptr inbounds ([280 x i8], [280 x i8]* @.str.6, i64 0, i64 0))
%22 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
%23 = call i32 @system(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
br label %28
24: ; preds = %16
%25 = call i32 @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.9, i64 0, i64 0))
%26 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %20
br label %29
29: ; preds = %28, %15
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"/dev/cpu/0/msr\00"
@F_OK = global i32 0
@W_OK = global i32 0
@.str.6 = [280 x i8] c"msr_major=202; \09\09\09\09\09\09\09cpuid_major=203; \09\09\09\09\09\09\09n=0; \09\09\09\09\09\09\09while [ $n -lt 16 ]; do \09\09\09\09\09\09\09\09mkdir -m 0755 -p /dev/cpu/$n; \09\09\09\09\09\09\09\09mknod /dev/cpu/$n/msr -m 0600 c $msr_major $n; \09\09\09\09\09\09\09\09mknod /dev/cpu/$n/cpuid -m 0444 c $cpuid_major $n; \09\09\09\09\09\09\09\09n=`expr $n + 1`; \09\09\09\09\09\09\09done; \09\09\09\09\09\09\09\00"
@.str.8 = [13 x i8] c"modprobe msr\00"
@str = [70 x i8] c"i7z DEBUG: msr device files DO NOT exist, trying out a makedev script\00"
@str.10 = [90 x i8] c"i7z DEBUG: You DO NOT have root privileges, mknod to create device entries won't work out\00"
@str.12 = [31 x i8] c"i7z DEBUG: modprobbing for msr\00"
@str.13 = [49 x i8] c"i7z DEBUG: msr device files exist /dev/cpu/*/msr\00"
@str.14 = [65 x i8] c"i7z DEBUG: You DO NOT have write permissions to msr device files\00"
@str.15 = [53 x i8] c"i7z DEBUG: A solution is to run this program as root\00"
@str.16 = [58 x i8] c"i7z DEBUG: You have write permissions to msr device files\00"
define void @Test_Or_Make_MSR_DEVICE_FILES() {
%1 = load i32, i32* @F_OK
%2 = tail call i64 @access(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %15
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.13, i64 0, i64 0))
%6 = load i32, i32* @W_OK
%7 = tail call i64 @access(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.16, i64 0, i64 0))
br label %27
11: ; preds = %4
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str.14, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.15, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str, i64 0, i64 0))
%17 = tail call i64 (...) @geteuid()
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = tail call i32 @system(i8* getelementptr inbounds ([280 x i8], [280 x i8]* @.str.6, i64 0, i64 0))
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.12, i64 0, i64 0))
%22 = tail call i32 @system(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
br label %27
23: ; preds = %15
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([90 x i8], [90 x i8]* @str.10, i64 0, i64 0))
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.15, i64 0, i64 0))
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %19, %9
ret void
}