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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int sys_cpu_pstate(int min, int max, int turbo) {
  FILE *f;
  f = fopen("/sys/devices/system/cpu/intel_pstate/min_perf_pct", "w");
  if (!f)
    return 0;
  fprintf(f, "%i\n", min);
  fclose(f);
  f = fopen("/sys/devices/system/cpu/intel_pstate/max_perf_pct", "w");
  if (!f)
    return 0;
  fprintf(f, "%i\n", max);
  fclose(f);
  f = fopen("/sys/devices/system/cpu/intel_pstate/no_turbo", "w");
  if (!f)
    return 0;
  fprintf(f, "%i\n", turbo ? 0 : 1);
  fclose(f);
  return 1;
}


x86 assembly (clang, -O0):
<sys_cpu_pstate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    0xeb8(%rip),%rdi
lea    0xee3(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116f <sys_cpu_pstate+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    1233 <sys_cpu_pstate+0x103>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xeb7(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xea6(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b9 <sys_cpu_pstate+0x89>
movl   $0x0,-0x4(%rbp)
jmp    1233 <sys_cpu_pstate+0x103>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe6d(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe8e(%rip),%rdi
lea    0xe4f(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1203 <sys_cpu_pstate+0xd3>
movl   $0x0,-0x4(%rbp)
jmp    1233 <sys_cpu_pstate+0x103>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%ecx
mov    $0x1,%edx
xor    %eax,%eax
cmp    $0x0,%ecx
cmovne %eax,%edx
lea    0xe16(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_cpu_pstate>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%ebx
lea    0xeb9(%rip),%rdi
lea    0xee4(%rip),%rsi
call   1050 <fopen@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     11f0 <sys_cpu_pstate+0xc0>
mov    %rax,%rbp
lea    0xecb(%rip),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   1040 <fprintf@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
lea    0xeb6(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11f0 <sys_cpu_pstate+0xc0>
mov    %rax,%rbx
lea    0xe97(%rip),%rsi
mov    %rax,%rdi
mov    %r15d,%edx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xeb3(%rip),%rdi
lea    0xe74(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11f0 <sys_cpu_pstate+0xc0>
mov    %rax,%rbx
xor    %edx,%edx
test   %r14d,%r14d
sete   %dl
lea    0xe5a(%rip),%rsi
mov    %rax,%rdi
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"/sys/devices/system/cpu/intel_pstate/min_perf_pct\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%i\0A\00"
@.str.3 = [50 x i8] c"/sys/devices/system/cpu/intel_pstate/max_perf_pct\00"
@.str.4 = [46 x i8] c"/sys/devices/system/cpu/intel_pstate/no_turbo\00"
define i32 @sys_cpu_pstate(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = call i32* @fopen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %8
%10 = load i32*, i32** %8
%11 = icmp ne i32* %10, null
br i1 %11, label %13, label %12
12: ; preds = %3
store i32 0, i32* %4
br label %42
13: ; preds = %3
%14 = load i32*, i32** %8
%15 = load i32, i32* %5
%16 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = load i32*, i32** %8
%18 = call i32 @fclose(i32* %17)
%19 = call i32* @fopen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %8
%20 = load i32*, i32** %8
%21 = icmp ne i32* %20, null
br i1 %21, label %23, label %22
22: ; preds = %13
store i32 0, i32* %4
br label %42
23: ; preds = %13
%24 = load i32*, i32** %8
%25 = load i32, i32* %6
%26 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = load i32*, i32** %8
%28 = call i32 @fclose(i32* %27)
%29 = call i32* @fopen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %8
%30 = load i32*, i32** %8
%31 = icmp ne i32* %30, null
br i1 %31, label %33, label %32
32: ; preds = %23
store i32 0, i32* %4
br label %42
33: ; preds = %23
%34 = load i32*, i32** %8
%35 = load i32, i32* %7
%36 = icmp ne i32 %35, 0
%37 = zext i1 %36 to i64
%38 = select i1 %36, i32 0, i32 1
%39 = call i32 @fprintf(i32* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = load i32*, i32** %8
%41 = call i32 @fclose(i32* %40)
store i32 1, i32* %4
br label %42
42: ; preds = %33, %32, %22, %12
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
@.str = [50 x i8] c"/sys/devices/system/cpu/intel_pstate/min_perf_pct\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%i\0A\00"
@.str.3 = [50 x i8] c"/sys/devices/system/cpu/intel_pstate/max_perf_pct\00"
@.str.4 = [46 x i8] c"/sys/devices/system/cpu/intel_pstate/no_turbo\00"
define i32 @sys_cpu_pstate(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %21, label %6
6: ; preds = %3
%7 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%8 = tail call i32 @fclose(i32* %4)
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %21, label %11
11: ; preds = %6
%12 = tail call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%13 = tail call i32 @fclose(i32* %9)
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %21, label %16
16: ; preds = %11
%17 = icmp eq i32 %2, 0
%18 = zext i1 %17 to i32
%19 = tail call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = tail call i32 @fclose(i32* %14)
br label %21
21: ; preds = %11, %6, %3, %16
%22 = phi i32 [ 1, %16 ], [ 0, %3 ], [ 0, %6 ], [ 0, %11 ]
ret i32 %22
}