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

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int sysctlnametomib(char *, int *, size_t *);
int get_mib_for_cpu_freq(int *mib, size_t miblen, int cpu, int *error) {
  char sysctl_freq[32];
  size_t len = miblen;
  snprintf(sysctl_freq, sizeof(sysctl_freq) / sizeof(sysctl_freq[0]),
           "dev.cpu.%d.freq", cpu);
  *error = sysctlnametomib(sysctl_freq, mib, &len);
  return len;
}


x86 assembly (clang, -O0):
<get_mib_for_cpu_freq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x20,%esi
lea    0xeae(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    -0x48(%rbp),%rdx
call   1040 <sysctlnametomib@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x48(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mib_for_cpu_freq>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rcx,%r14
mov    %edx,%ecx
mov    %rdi,%rbx
mov    %rsi,0x8(%rsp)
lea    0xec3(%rip),%rdx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x20,%esi
call   1030 <snprintf@plt>
lea    0x8(%rsp),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <sysctlnametomib@plt>
mov    %eax,(%r14)
mov    0x8(%rsp),%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"dev.cpu.%d.freq\00"
define i32 @get_mib_for_cpu_freq(i32* %0, i64 %1, i32 %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32*
%9 = alloca [32 x i8]
%10 = alloca i64
store i32* %0, i32** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%11 = load i64, i64* %6
store i64 %11, i64* %10
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%13 = load i32, i32* %7
%14 = call i32 @snprintf(i8* %12, i32 32, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%16 = load i32*, i32** %5
%17 = call i32 @sysctlnametomib(i8* %15, i32* %16, i64* %10)
%18 = load i32*, i32** %8
store i32 %17, i32* %18
%19 = load i64, i64* %10
%20 = trunc i64 %19 to i32
ret i32 %20
}

LLVM IR (-O2):
@.str = [16 x i8] c"dev.cpu.%d.freq\00"
define i32 @get_mib_for_cpu_freq(i32* %0, i64 %1, i32 %2, i32* nocapture writeonly %3) {
%5 = alloca [32 x i8]
%6 = alloca i64
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%8 = bitcast i64* %6 to i8*
store i64 %1, i64* %6
%9 = call i32 @snprintf(i8* %7, i32 32, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %2)
%10 = call i32 @sysctlnametomib(i8* %7, i32* %0, i64* %6)
store i32 %10, i32* %3
%11 = load i64, i64* %6
%12 = trunc i64 %11 to i32
ret i32 %12
}