#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 /*<<< orphan*/ adjust_scaling_min_from_base_freq(int);
int get_physical_die_id(int);
int get_physical_package_id(int);
int get_topo_max_cpus();
int /*<<< orphan*/ set_cpufreq_scaling_min_max_from_cpuinfo(int, int,
                                                            int /*<<< orphan*/);
void set_scaling_min_to_cpuinfo_max(int cpu) {
  int i, pkg_id, die_id;
  pkg_id = get_physical_package_id(cpu);
  die_id = get_physical_die_id(cpu);
  for (i = 0; i < get_topo_max_cpus(); ++i) {
    if (pkg_id != get_physical_package_id(i) ||
        die_id != get_physical_die_id(i))
      continue;
    set_cpufreq_scaling_min_max_from_cpuinfo(i, 1, 0);
    adjust_scaling_min_from_base_freq(i);
  }
}


x86 assembly (clang, -O0):
<set_scaling_min_to_cpuinfo_max>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <get_physical_package_id@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <get_physical_die_id@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1070 <get_topo_max_cpus@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    11f2 <set_scaling_min_to_cpuinfo_max+0xa2>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <get_physical_package_id@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jne    11c8 <set_scaling_min_to_cpuinfo_max+0x78>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <get_physical_die_id@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
je     11cd <set_scaling_min_to_cpuinfo_max+0x7d>
jmp    11e4 <set_scaling_min_to_cpuinfo_max+0x94>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1050 <set_cpufreq_scaling_min_max_from_cpuinfo@plt>
mov    -0x8(%rbp),%edi
call   1030 <adjust_scaling_min_from_base_freq@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1178 <set_scaling_min_to_cpuinfo_max+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_scaling_min_to_cpuinfo_max>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
call   1040 <get_physical_package_id@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1060 <get_physical_die_id@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1070 <get_topo_max_cpus@plt>
test   %eax,%eax
jle    11bc <set_scaling_min_to_cpuinfo_max+0x6c>
xor    %ebp,%ebp
jmp    118e <set_scaling_min_to_cpuinfo_max+0x3e>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
xor    %eax,%eax
call   1070 <get_topo_max_cpus@plt>
cmp    %eax,%ebp
jge    11bc <set_scaling_min_to_cpuinfo_max+0x6c>
mov    %ebp,%edi
call   1040 <get_physical_package_id@plt>
cmp    %eax,%ebx
jne    1180 <set_scaling_min_to_cpuinfo_max+0x30>
mov    %ebp,%edi
call   1060 <get_physical_die_id@plt>
cmp    %eax,%r14d
jne    1180 <set_scaling_min_to_cpuinfo_max+0x30>
mov    %ebp,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1050 <set_cpufreq_scaling_min_max_from_cpuinfo@plt>
mov    %ebp,%edi
call   1030 <adjust_scaling_min_from_base_freq@plt>
jmp    1180 <set_scaling_min_to_cpuinfo_max+0x30>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @set_scaling_min_to_cpuinfo_max(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = call i32 @get_physical_package_id(i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %2
%9 = call i32 @get_physical_die_id(i32 %8)
store i32 %9, i32* %5
store i32 0, i32* %3
br label %10
10: ; preds = %30, %1
%11 = load i32, i32* %3
%12 = call i32 (...) @get_topo_max_cpus()
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %33
14: ; preds = %10
%15 = load i32, i32* %4
%16 = load i32, i32* %3
%17 = call i32 @get_physical_package_id(i32 %16)
%18 = icmp ne i32 %15, %17
br i1 %18, label %24, label %19
19: ; preds = %14
%20 = load i32, i32* %5
%21 = load i32, i32* %3
%22 = call i32 @get_physical_die_id(i32 %21)
%23 = icmp ne i32 %20, %22
br i1 %23, label %24, label %25
24: ; preds = %19, %14
br label %30
25: ; preds = %19
%26 = load i32, i32* %3
%27 = call i32 @set_cpufreq_scaling_min_max_from_cpuinfo(i32 %26, i32 1, i32 0)
%28 = load i32, i32* %3
%29 = call i32 @adjust_scaling_min_from_base_freq(i32 %28)
br label %30
30: ; preds = %25, %24
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %10
33: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @set_scaling_min_to_cpuinfo_max(i32 %0) {
%2 = tail call i32 @get_physical_package_id(i32 %0)
%3 = tail call i32 @get_physical_die_id(i32 %0)
%4 = tail call i32 (...) @get_topo_max_cpus()
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %20
6: ; preds = %1, %16
%7 = phi i32 [ %17, %16 ], [ 0, %1 ]
%8 = tail call i32 @get_physical_package_id(i32 %7)
%9 = icmp eq i32 %2, %8
br i1 %9, label %10, label %16
10: ; preds = %6
%11 = tail call i32 @get_physical_die_id(i32 %7)
%12 = icmp eq i32 %3, %11
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = tail call i32 @set_cpufreq_scaling_min_max_from_cpuinfo(i32 %7, i32 1, i32 0)
%15 = tail call i32 @adjust_scaling_min_from_base_freq(i32 %7)
br label %16
16: ; preds = %6, %10, %13
%17 = add nuw nsw i32 %7, 1
%18 = tail call i32 (...) @get_topo_max_cpus()
%19 = icmp slt i32 %17, %18
br i1 %19, label %6, label %20
20: ; preds = %16, %1
ret void
}