#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);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ geteuid();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int 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 {
      fprintf(
          stderr,
          "i7z DEBUG: You DO NOT have write permissions to msr device files\n");
      fprintf(stderr, "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) {
      (void)(system(
                 "	#! /bin/bash	\n	msr_major=202;	\n	"
                 "cpuid_major=203;\n	n=0;			\n	while "
                 "[ $n -lt 16 ]; do \n		mkdir -m 0755 -p /dev/cpu/$n; "
                 "\n		mknod /dev/cpu/$n/msr -m 0600 c $msr_major $n; "
                 "\n		mknod /dev/cpu/$n/cpuid -m 0444 c $cpuid_major "
                 "$n; \n		n=$((n + 1)); \n	done; \n") +
             1);
      printf("i7z DEBUG: modprobbing for msr\n");
      if (system("modprobe msr") == -1)
        fprintf(stderr, "i7z DEBUG: modprobbing for msr failed - do you have "
                        "CONFIG_X86_MSR option enabled for your kernel?\n");
    } else {
      fprintf(stderr, "i7z DEBUG: You DO NOT have root privileges, mknod to "
                      "create device entries won't work out\n");
      fprintf(stderr, "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    0x2e5d(%rip),%rax
mov    (%rax),%esi
lea    0xe8c(%rip),%rdi
call   1070 <access@plt>
cmp    $0x0,%rax
jne    11f8 <Test_Or_Make_MSR_DEVICE_FILES+0x98>
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    0xe61(%rip),%rdi
call   1070 <access@plt>
cmp    $0x0,%rax
jne    11bf <Test_Or_Make_MSR_DEVICE_FILES+0x5f>
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
jmp    11f3 <Test_Or_Make_MSR_DEVICE_FILES+0x93>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xead(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    0xeda(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1295 <Test_Or_Make_MSR_DEVICE_FILES+0x135>
lea    0xef5(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <geteuid@plt>
cmp    $0x0,%rax
jne    125c <Test_Or_Make_MSR_DEVICE_FILES+0xfc>
lea    0xf1f(%rip),%rdi
call   1030 <system@plt>
lea    0x100b(%rip),%rdi
call   1040 <printf@plt>
lea    0x101f(%rip),%rdi
call   1030 <system@plt>
cmp    $0xffffffff,%eax
jne    1257 <Test_Or_Make_MSR_DEVICE_FILES+0xf7>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
lea    0x100e(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1290 <Test_Or_Make_MSR_DEVICE_FILES+0x130>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    0x1058(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1295 <Test_Or_Make_MSR_DEVICE_FILES+0x135>
pop    %rbp
ret

x86 assembly (clang, -O2):
<Test_Or_Make_MSR_DEVICE_FILES>:
push   %rbx
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
lea    0xe8f(%rip),%rdi
call   1070 <access@plt>
test   %rax,%rax
je     11be <Test_Or_Make_MSR_DEVICE_FILES+0x5e>
lea    0x10c9(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <geteuid@plt>
test   %rax,%rax
jne    1207 <Test_Or_Make_MSR_DEVICE_FILES+0xa7>
lea    0xeed(%rip),%rdi
call   1040 <system@plt>
lea    0x10eb(%rip),%rdi
call   1030 <puts@plt>
lea    0xfcd(%rip),%rdi
call   1040 <system@plt>
cmp    $0xffffffff,%eax
je     11f1 <Test_Or_Make_MSR_DEVICE_FILES+0x91>
pop    %rbx
ret
lea    0x10eb(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
lea    0xe26(%rip),%rdi
call   1070 <access@plt>
test   %rax,%rax
jne    1219 <Test_Or_Make_MSR_DEVICE_FILES+0xb9>
lea    0x10f6(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
lea    0xf8b(%rip),%rsi
pop    %rbx
jmp    1060 <fprintf@plt>
mov    0x2dca(%rip),%rbx
mov    (%rbx),%edi
lea    0xfd9(%rip),%rsi
jmp    1229 <Test_Or_Make_MSR_DEVICE_FILES+0xc9>
mov    0x2db8(%rip),%rbx
mov    (%rbx),%edi
lea    0xde6(%rip),%rsi
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe1a(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <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"
@stderr = global i32 0
@.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 = [248 x i8] c"\09#! /bin/bash\09\0A\09msr_major=202;\09\0A\09cpuid_major=203;\0A\09n=0;\09\09\09\0A\09while [ $n -lt 16 ]; do \0A\09\09mkdir -m 0755 -p /dev/cpu/$n; \0A\09\09mknod /dev/cpu/$n/msr -m 0600 c $msr_major $n; \0A\09\09mknod /dev/cpu/$n/cpuid -m 0444 c $cpuid_major $n; \0A\09\09n=$((n + 1)); \0A\09done; \0A\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 = [100 x i8] c"i7z DEBUG: modprobbing for msr failed - do you have CONFIG_X86_MSR option enabled for your kernel?\0A\00"
@.str.10 = [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 %18
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 %17
11: ; preds = %4
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0))
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %9
br label %39
18: ; preds = %0
%19 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.5, i64 0, i64 0))
%20 = call i64 (...) @geteuid()
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = call i32 @system(i8* getelementptr inbounds ([248 x i8], [248 x i8]* @.str.6, i64 0, i64 0))
%24 = add nsw i32 %23, 1
%25 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
%26 = call i32 @system(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str.9, i64 0, i64 0))
br label %31
31: ; preds = %28, %22
br label %38
32: ; preds = %18
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.10, i64 0, i64 0))
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %31
br label %39
39: ; preds = %38, %17
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
@stderr = global i32 0
@.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.6 = [248 x i8] c"\09#! /bin/bash\09\0A\09msr_major=202;\09\0A\09cpuid_major=203;\0A\09n=0;\09\09\09\0A\09while [ $n -lt 16 ]; do \0A\09\09mkdir -m 0755 -p /dev/cpu/$n; \0A\09\09mknod /dev/cpu/$n/msr -m 0600 c $msr_major $n; \0A\09\09mknod /dev/cpu/$n/cpuid -m 0444 c $cpuid_major $n; \0A\09\09n=$((n + 1)); \0A\09done; \0A\00"
@.str.8 = [13 x i8] c"modprobe msr\00"
@.str.9 = [100 x i8] c"i7z DEBUG: modprobbing for msr failed - do you have CONFIG_X86_MSR option enabled for your kernel?\0A\00"
@.str.10 = [91 x i8] c"i7z DEBUG: You DO NOT have root privileges, mknod to create device entries won't work out\0A\00"
@str = [70 x i8] c"i7z DEBUG: msr device files DO NOT exist, trying out a makedev script\00"
@str.11 = [31 x i8] c"i7z DEBUG: modprobbing for msr\00"
@str.12 = [49 x i8] c"i7z DEBUG: msr device files exist /dev/cpu/*/msr\00"
@str.13 = [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 %17
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.12, 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.13, i64 0, i64 0))
br label %35
11: ; preds = %4
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0))
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str, i64 0, i64 0))
%19 = tail call i64 (...) @geteuid()
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = tail call i32 @system(i8* getelementptr inbounds ([248 x i8], [248 x i8]* @.str.6, i64 0, i64 0))
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.11, i64 0, i64 0))
%24 = tail call i32 @system(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %35
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str.9, i64 0, i64 0))
br label %35
29: ; preds = %17
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.10, i64 0, i64 0))
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0))
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %26, %21, %9
ret void
}