#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 scalar_t__ uid_t;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ geteuid();
scalar_t__ getuid();
int /*<<< orphan*/ mbp_log(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ *opendir(char *);
void check_requirements(const char *program_path) {
  uid_t uid = getuid(), euid = geteuid();
  if (uid != 0 || euid != 0) {
    mbp_log(LOG_ERR,
            "%s needs root privileges. Please run %s as root. Exiting.",
            program_path, program_path);
    exit(EXIT_FAILURE);
  }
  DIR *dir = opendir("/sys/devices/platform/coretemp.0");
  if (ENOENT == errno) {
    mbp_log(LOG_ERR,
            "%s needs coretemp support. Please either load it or build it into "
            "the kernel. Exiting.",
            program_path);
    exit(EXIT_FAILURE);
  }
  closedir(dir);
  dir = opendir("/sys/devices/platform/applesmc.768");
  if (ENOENT == errno) {
    mbp_log(LOG_ERR,
            "%s needs applesmc support. Please either load it or build it into "
            "the kernel. Exiting.",
            program_path);
    exit(EXIT_FAILURE);
  }
  closedir(dir);
}


x86 assembly (clang, -O0):
<check_requirements>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1198 <check_requirements+0x38>
cmpq   $0x0,-0x18(%rbp)
je     11c5 <check_requirements+0x65>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1070 <mbp_log@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xe6e(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x20(%rbp)
mov    0x2dec(%rip),%rax
mov    (%rax),%rax
mov    0x2dfa(%rip),%rcx
cmp    (%rcx),%rax
jne    1218 <check_requirements+0xb8>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1070 <mbp_log@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1060 <closedir@plt>
lea    0xe8a(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x20(%rbp)
mov    0x2d90(%rip),%rax
mov    (%rax),%rax
mov    0x2d9e(%rip),%rcx
cmp    (%rcx),%rax
jne    1274 <check_requirements+0x114>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe76(%rip),%rsi
mov    $0x0,%al
call   1070 <mbp_log@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1060 <closedir@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_requirements>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <geteuid@plt>
or     %rbx,%rax
jne    11c9 <check_requirements+0x69>
lea    0xeb5(%rip),%rdi
call   1030 <opendir@plt>
mov    0x2e37(%rip),%r15
mov    (%r15),%rcx
mov    0x2e45(%rip),%rbx
cmp    (%rbx),%rcx
je     11e8 <check_requirements+0x88>
mov    %rax,%rdi
call   1060 <closedir@plt>
lea    0xf03(%rip),%rdi
call   1030 <opendir@plt>
mov    (%r15),%rcx
cmp    (%rbx),%rcx
je     11fa <check_requirements+0x9a>
mov    %rax,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <closedir@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
mov    %r14,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1070 <mbp_log@plt>
jmp    1214 <check_requirements+0xb4>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
jmp    120a <check_requirements+0xaa>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    0xecb(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <mbp_log@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [58 x i8] c"%s needs root privileges. Please run %s as root. Exiting.\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [33 x i8] c"/sys/devices/platform/coretemp.0\00"
@ENOENT = global i64 0
@errno = global i64 0
@.str.2 = [87 x i8] c"%s needs coretemp support. Please either load it or build it into the kernel. Exiting.\00"
@.str.3 = [35 x i8] c"/sys/devices/platform/applesmc.768\00"
@.str.4 = [87 x i8] c"%s needs applesmc support. Please either load it or build it into the kernel. Exiting.\00"
define void @check_requirements(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32*
store i8* %0, i8** %2
%6 = call i64 (...) @getuid()
store i64 %6, i64* %3
%7 = call i64 (...) @geteuid()
store i64 %7, i64* %4
%8 = load i64, i64* %3
%9 = icmp ne i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = load i64, i64* %4
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %10, %1
%14 = load i32, i32* @LOG_ERR
%15 = load i8*, i8** %2
%16 = load i8*, i8** %2
%17 = call i32 (i32, i8*, i8*, ...) @mbp_log(i32 %14, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %10
%21 = call i32* @opendir(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %5
%22 = load i64, i64* @ENOENT
%23 = load i64, i64* @errno
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %31
25: ; preds = %20
%26 = load i32, i32* @LOG_ERR
%27 = load i8*, i8** %2
%28 = call i32 (i32, i8*, i8*, ...) @mbp_log(i32 %26, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %20
%32 = load i32*, i32** %5
%33 = call i32 @closedir(i32* %32)
%34 = call i32* @opendir(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
store i32* %34, i32** %5
%35 = load i64, i64* @ENOENT
%36 = load i64, i64* @errno
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %44
38: ; preds = %31
%39 = load i32, i32* @LOG_ERR
%40 = load i8*, i8** %2
%41 = call i32 (i32, i8*, i8*, ...) @mbp_log(i32 %39, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.4, i64 0, i64 0), i8* %40)
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %31
%45 = load i32*, i32** %5
%46 = call i32 @closedir(i32* %45)
ret void
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [58 x i8] c"%s needs root privileges. Please run %s as root. Exiting.\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [33 x i8] c"/sys/devices/platform/coretemp.0\00"
@ENOENT = global i64 0
@errno = global i64 0
@.str.2 = [87 x i8] c"%s needs coretemp support. Please either load it or build it into the kernel. Exiting.\00"
@.str.3 = [35 x i8] c"/sys/devices/platform/applesmc.768\00"
@.str.4 = [87 x i8] c"%s needs applesmc support. Please either load it or build it into the kernel. Exiting.\00"
define void @check_requirements(i8* %0) {
%2 = tail call i64 (...) @getuid()
%3 = tail call i64 (...) @geteuid()
%4 = icmp ne i64 %2, 0
%5 = icmp ne i64 %3, 0
%6 = select i1 %4, i1 true, i1 %5
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i32, i32* @LOG_ERR
%9 = tail call i32 (i32, i8*, i8*, ...) @mbp_log(i32 %8, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %0)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %1
%13 = tail call i32* @opendir(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%14 = load i64, i64* @ENOENT
%15 = load i64, i64* @errno
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = load i32, i32* @LOG_ERR
%19 = tail call i32 (i32, i8*, i8*, ...) @mbp_log(i32 %18, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %12
%23 = tail call i32 @closedir(i32* %13)
%24 = tail call i32* @opendir(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%25 = load i64, i64* @ENOENT
%26 = load i64, i64* @errno
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %33
28: ; preds = %22
%29 = load i32, i32* @LOG_ERR
%30 = tail call i32 (i32, i8*, i8*, ...) @mbp_log(i32 %29, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%31 = load i32, i32* @EXIT_FAILURE
%32 = tail call i32 @exit(i32 %31)
unreachable
33: ; preds = %22
%34 = tail call i32 @closedir(i32* %24)
ret void
}