#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*/ filename;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
scalar_t__ sys_cpu_setall(char const *, char const *);
int sys_cpufreq_set(const char *control, const char *value) {
  char filename[4096];
  FILE *f;
  snprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpufreq/%s",
           control);
  f = fopen(filename, "w");
  if (!f) {
    if (sys_cpu_setall(control, value) > 0)
      return 1;
    else
      return -1;
  }
  fprintf(f, "%s\n", value);
  fclose(f);
  return 1;
}


x86 assembly (clang, -O0):
<sys_cpufreq_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1000,%esi
lea    0xe86(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x1020(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x1028(%rbp)
cmpq   $0x0,-0x1028(%rbp)
jne    11d6 <sys_cpufreq_set+0x86>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <sys_cpu_setall@plt>
cmp    $0x0,%rax
jle    11ca <sys_cpufreq_set+0x7a>
movl   $0x1,-0x4(%rbp)
jmp    1200 <sys_cpufreq_set+0xb0>
movl   $0xffffffff,-0x4(%rbp)
jmp    1200 <sys_cpufreq_set+0xb0>
mov    -0x1028(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe3d(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x1028(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_cpufreq_set>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe97(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r15,%rcx
call   1040 <snprintf@plt>
lea    0xea0(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11b4 <sys_cpufreq_set+0x64>
mov    %rax,%rbx
lea    0xe8b(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
jmp    11cd <sys_cpufreq_set+0x7d>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <sys_cpu_setall@plt>
xor    %ecx,%ecx
test   %rax,%rax
setg   %cl
lea    (%rcx,%rcx,1),%eax
add    $0xffffffff,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [35 x i8] c"/sys/devices/system/cpu/cpufreq/%s\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @sys_cpufreq_set(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [4096 x i8]
%7 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%9 = load i8*, i8** %4
%10 = call i32 @snprintf(i8* %8, i32 4096, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %7
%13 = load i32*, i32** %7
%14 = icmp ne i32* %13, null
br i1 %14, label %22, label %15
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = load i8*, i8** %5
%18 = call i64 @sys_cpu_setall(i8* %16, i8* %17)
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 1, i32* %3
br label %28
21: ; preds = %15
store i32 -1, i32* %3
br label %28
22: ; preds = %2
%23 = load i32*, i32** %7
%24 = load i8*, i8** %5
%25 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = load i32*, i32** %7
%27 = call i32 @fclose(i32* %26)
store i32 1, i32* %3
br label %28
28: ; preds = %22, %21, %20
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [35 x i8] c"/sys/devices/system/cpu/cpufreq/%s\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @sys_cpufreq_set(i8* %0, i8* %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 4096, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = call i64 @sys_cpu_setall(i8* %0, i8* %1)
%10 = icmp sgt i64 %9, 0
%11 = select i1 %10, i32 1, i32 -1
br label %15
12: ; preds = %2
%13 = call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%14 = call i32 @fclose(i32* %6)
br label %15
15: ; preds = %8, %12
%16 = phi i32 [ 1, %12 ], [ %11, %8 ]
ret i32 %16
}