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

/* Variables and functions */
int EINVAL;
scalar_t__ ERANGE;
scalar_t__ errno;
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
scalar_t__ strcmp(char *, char const *);
unsigned long strtoul(char *, char **, int /*<<< orphan*/);
scalar_t__ sysfs_read_file(char *, char *, int);
int sysfs_get_sched(const char *smt_mc) {
  unsigned long value;
  char linebuf[255];
  char *endp;
  char path[255];
  if (strcmp("mc", smt_mc) && strcmp("smt", smt_mc))
    return -EINVAL;
  snprintf(path, sizeof(path),
           "/sys/devices/system/cpu/"
           "sched_%s_power_savings",
           smt_mc);
  if (sysfs_read_file(path, linebuf, 255) == 0)
    return -1;
  value = strtoul(linebuf, &endp, 0);
  if (endp == linebuf || errno == ERANGE)
    return -1;
  return value;
}


x86 assembly (clang, -O0):
<sysfs_get_sched>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea6(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1196 <sysfs_get_sched+0x56>
mov    -0x10(%rbp),%rsi
lea    0xe8f(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1196 <sysfs_get_sched+0x56>
xor    %eax,%eax
mov    0x2e44(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    123d <sysfs_get_sched+0xfd>
lea    -0x230(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0xff,%esi
lea    0xe5a(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x230(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0xff,%edx
call   1040 <sysfs_read_file@plt>
cmp    $0x0,%rax
jne    11e0 <sysfs_get_sched+0xa0>
movl   $0xffffffff,-0x4(%rbp)
jmp    123d <sysfs_get_sched+0xfd>
lea    -0x120(%rbp),%rdi
lea    -0x128(%rbp),%rsi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %rax,-0x18(%rbp)
mov    -0x128(%rbp),%rax
lea    -0x120(%rbp),%rcx
cmp    %rcx,%rax
je     122a <sysfs_get_sched+0xea>
mov    0x2dc1(%rip),%rax
mov    (%rax),%rax
mov    0x2dc7(%rip),%rcx
cmp    (%rcx),%rax
jne    1236 <sysfs_get_sched+0xf6>
movl   $0xffffffff,-0x4(%rbp)
jmp    123d <sysfs_get_sched+0xfd>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysfs_get_sched>:
push   %r15
push   %r14
push   %rbx
sub    $0x210,%rsp
mov    %rdi,%rbx
lea    0xeaa(%rip),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1184 <sysfs_get_sched+0x44>
lea    0xe99(%rip),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1184 <sysfs_get_sched+0x44>
mov    0x2e52(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
jmp    11f4 <sysfs_get_sched+0xb4>
lea    0xe7c(%rip),%rdx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0xff,%esi
mov    %rbx,%rcx
call   1030 <snprintf@plt>
lea    0x110(%rsp),%r14
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0xff,%edx
call   1040 <sysfs_read_file@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     11f4 <sysfs_get_sched+0xb4>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
xor    %edx,%edx
call   1060 <strtoul@plt>
cmp    %r14,0x8(%rsp)
je     11f4 <sysfs_get_sched+0xb4>
mov    0x2df9(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2dff(%rip),%rdx
cmp    (%rdx),%rcx
mov    $0xffffffff,%ebx
cmovne %eax,%ebx
mov    %ebx,%eax
add    $0x210,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"mc\00"
@.str.1 = [4 x i8] c"smt\00"
@EINVAL = global i32 0
@.str.2 = [47 x i8] c"/sys/devices/system/cpu/sched_%s_power_savings\00"
@errno = global i64 0
@ERANGE = global i64 0
define i32 @sysfs_get_sched(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [255 x i8]
%6 = alloca i8*
%7 = alloca [255 x i8]
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i64 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* @EINVAL
%17 = sub nsw i32 0, %16
store i32 %17, i32* %2
br label %41
18: ; preds = %11, %1
%19 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%20 = load i8*, i8** %3
%21 = call i32 @snprintf(i8* %19, i32 255, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%23 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%24 = call i64 @sysfs_read_file(i8* %22, i8* %23, i32 255)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %18
store i32 -1, i32* %2
br label %41
27: ; preds = %18
%28 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%29 = call i64 @strtoul(i8* %28, i8** %6, i32 0)
store i64 %29, i64* %4
%30 = load i8*, i8** %6
%31 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%32 = icmp eq i8* %30, %31
br i1 %32, label %37, label %33
33: ; preds = %27
%34 = load i64, i64* @errno
%35 = load i64, i64* @ERANGE
%36 = icmp eq i64 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %33, %27
store i32 -1, i32* %2
br label %41
38: ; preds = %33
%39 = load i64, i64* %4
%40 = trunc i64 %39 to i32
store i32 %40, i32* %2
br label %41
41: ; preds = %38, %37, %26, %15
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@.str = [3 x i8] c"mc\00"
@.str.1 = [4 x i8] c"smt\00"
@EINVAL = global i32 0
@.str.2 = [47 x i8] c"/sys/devices/system/cpu/sched_%s_power_savings\00"
@errno = global i64 0
@ERANGE = global i64 0
define i32 @sysfs_get_sched(i8* %0) {
%2 = alloca [255 x i8]
%3 = alloca i8*
%4 = alloca [255 x i8]
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%6 = bitcast i8** %3 to i8*
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%8 = tail call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %1
%11 = tail call i64 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = load i32, i32* @EINVAL
%15 = sub nsw i32 0, %14
br label %30
16: ; preds = %10, %1
%17 = call i32 @snprintf(i8* %7, i32 255, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%18 = call i64 @sysfs_read_file(i8* %7, i8* %5, i32 255)
%19 = icmp eq i64 %18, 0
br i1 %19, label %30, label %20
20: ; preds = %16
%21 = call i64 @strtoul(i8* %5, i8** %3, i32 0)
%22 = load i8*, i8** %3
%23 = icmp eq i8* %22, %5
br i1 %23, label %30, label %24
24: ; preds = %20
%25 = load i64, i64* @errno
%26 = load i64, i64* @ERANGE
%27 = icmp eq i64 %25, %26
%28 = trunc i64 %21 to i32
%29 = select i1 %27, i32 -1, i32 %28
br label %30
30: ; preds = %24, %20, %16, %13
%31 = phi i32 [ %15, %13 ], [ -1, %16 ], [ -1, %20 ], [ %29, %24 ]
ret i32 %31
}