#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*/ _SC_NPROCESSORS_CONF;
int /*<<< orphan*/ printf(char *, ...);
int readint(int /*<<< orphan*/);
int /*<<< orphan*/ smprintf(char *, int);
int sysconf(int /*<<< orphan*/);
int get_cpufreq(void) {
  int max_cores = sysconf(_SC_NPROCESSORS_CONF);
  int i = 0;
  int cur_freq[32];
  float cur_freq_tmp;
  while (i < max_cores) {
    cur_freq[i] = readint(
        smprintf("/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_cur_freq", i));
    cur_freq_tmp = (float)cur_freq[i] / 1000000;
    printf("%1.1f;", cur_freq_tmp);
    ++i;
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<get_cpufreq>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
mov    %eax,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11db <get_cpufreq+0x9b>
mov    -0x8(%rbp),%esi
lea    0xe8b(%rip),%rdi
call   1030 <smprintf@plt>
mov    %eax,%edi
call   1050 <readint@plt>
mov    %eax,%ecx
movslq -0x8(%rbp),%rax
mov    %ecx,-0x90(%rbp,%rax,4)
movslq -0x8(%rbp),%rax
cvtsi2ssl -0x90(%rbp,%rax,4),%xmm0
ff ff
movss  0xe59(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x94(%rbp)
ff
movss  -0x94(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
lea    0xe75(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1163 <get_cpufreq+0x23>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpufreq>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
test   %eax,%eax
jle    11b5 <get_cpufreq+0x65>
mov    %eax,%ebx
xor    %ebp,%ebp
lea    0xe90(%rip),%r14
lea    0xec0(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <smprintf@plt>
mov    %eax,%edi
call   1060 <readint@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
divss  0xe60(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1180 <get_cpufreq+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@_SC_NPROCESSORS_CONF = global i32 0
@.str = [55 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_cur_freq\00"
@.str.1 = [7 x i8] c"%1.1f;\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @get_cpufreq() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [32 x i32]
%4 = alloca float
%5 = load i32, i32* @_SC_NPROCESSORS_CONF
%6 = call i32 @sysconf(i32 %5)
store i32 %6, i32* %1
store i32 0, i32* %2
br label %7
7: ; preds = %11, %0
%8 = load i32, i32* %2
%9 = load i32, i32* %1
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %29
11: ; preds = %7
%12 = load i32, i32* %2
%13 = call i32 @smprintf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 @readint(i32 %13)
%15 = load i32, i32* %2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 %16
store i32 %14, i32* %17
%18 = load i32, i32* %2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = sitofp i32 %21 to float
%23 = fdiv float %22, 1.000000e+06
store float %23, float* %4
%24 = load float, float* %4
%25 = fpext float %24 to double
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %25)
%27 = load i32, i32* %2
%28 = add nsw i32 %27, 1
store i32 %28, i32* %2
br label %7
29: ; preds = %7
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@_SC_NPROCESSORS_CONF = global i32 0
@.str = [55 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_cur_freq\00"
@.str.1 = [7 x i8] c"%1.1f;\00"
define i32 @get_cpufreq() {
%1 = load i32, i32* @_SC_NPROCESSORS_CONF
%2 = tail call i32 @sysconf(i32 %1)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %14
4: ; preds = %0, %4
%5 = phi i32 [ %12, %4 ], [ 0, %0 ]
%6 = tail call i32 @smprintf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = tail call i32 @readint(i32 %6)
%8 = sitofp i32 %7 to float
%9 = fdiv float %8, 1.000000e+06
%10 = fpext float %9 to double
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %10)
%12 = add nuw nsw i32 %5, 1
%13 = icmp eq i32 %12, %2
br i1 %13, label %14, label %4
14: ; preds = %4, %0
%15 = tail call i32 @putchar(i32 10)
ret i32 0
}