#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 get_cpufreq_base_freq(int);
scalar_t__ no_turbo();
int parse_int_file(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ set_cpufreq_scaling_min_max(int, int, int);
void adjust_scaling_max_from_base_freq(int cpu) {
  int base_freq, scaling_max_freq;
  scaling_max_freq = parse_int_file(
      0, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", cpu);
  base_freq = get_cpufreq_base_freq(cpu);
  if (scaling_max_freq < base_freq || no_turbo())
    set_cpufreq_scaling_min_max(cpu, 1, base_freq);
}


x86 assembly (clang, -O0):
<adjust_scaling_max_from_base_freq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edx
xor    %edi,%edi
lea    0xea9(%rip),%rsi
call   1030 <parse_int_file@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <get_cpufreq_base_freq@plt>
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     1187 <adjust_scaling_max_from_base_freq+0x47>
mov    $0x0,%al
call   1040 <no_turbo@plt>
cmp    $0x0,%rax
je     1197 <adjust_scaling_max_from_base_freq+0x57>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%edx
mov    $0x1,%esi
call   1060 <set_cpufreq_scaling_min_max@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adjust_scaling_max_from_base_freq>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
lea    0xeb3(%rip),%rsi
xor    %edi,%edi
mov    %ebx,%edx
call   1030 <parse_int_file@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <get_cpufreq_base_freq@plt>
mov    %eax,%r14d
cmp    %eax,%ebp
jl     1172 <adjust_scaling_max_from_base_freq+0x32>
xor    %eax,%eax
call   1040 <no_turbo@plt>
test   %rax,%rax
je     1185 <adjust_scaling_max_from_base_freq+0x45>
mov    %ebx,%edi
mov    $0x1,%esi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <set_cpufreq_scaling_min_max@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [55 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq\00"
define void @adjust_scaling_max_from_base_freq(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @parse_int_file(i32 0, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %4
%7 = load i32, i32* %2
%8 = call i32 @get_cpufreq_base_freq(i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %4
%10 = load i32, i32* %3
%11 = icmp slt i32 %9, %10
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = call i64 (...) @no_turbo()
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12, %1
%16 = load i32, i32* %2
%17 = load i32, i32* %3
%18 = call i32 @set_cpufreq_scaling_min_max(i32 %16, i32 1, i32 %17)
br label %19
19: ; preds = %15, %12
ret void
}

LLVM IR (-O2):
@.str = [55 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq\00"
define void @adjust_scaling_max_from_base_freq(i32 %0) {
%2 = tail call i32 @parse_int_file(i32 0, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = tail call i32 @get_cpufreq_base_freq(i32 %0)
%4 = icmp slt i32 %2, %3
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = tail call i64 (...) @no_turbo()
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %5, %1
%9 = tail call i32 @set_cpufreq_scaling_min_max(i32 %0, i32 1, i32 %3)
br label %10
10: ; preds = %8, %5
ret void
}