#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 */
struct sysentry {
  int dummy;
};

/* Variables and functions */
double get_delta_value(char *);
double get_scaled_tb();
double round_off_freq();
int /*<<< orphan*/ sprintf(char *, char *, double);
void get_cpu_idle_spurr(struct sysentry *unused_se, char *buf) {
  double delta_tb, delta_spurr, delta_idle_spurr;
  double physc, idle;
  double rfreq;
  delta_tb = get_scaled_tb();
  delta_spurr = get_delta_value("spurr");
  delta_idle_spurr = get_delta_value("idle_spurr");
  physc = (delta_spurr - delta_idle_spurr) / delta_tb;
  idle = (delta_spurr / delta_tb) - physc;
  idle *= 100.00;
  rfreq = round_off_freq();
  idle += ((idle * rfreq) / 100);
  sprintf(buf, "%.2f", idle);
}


x86 assembly (clang, -O0):
<get_cpu_idle_spurr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <get_scaled_tb@plt>
movsd  %xmm0,-0x18(%rbp)
lea    0xeaa(%rip),%rdi
call   1050 <get_delta_value@plt>
movsd  %xmm0,-0x20(%rbp)
lea    0xe94(%rip),%rdi
call   1050 <get_delta_value@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe52(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1040 <round_off_freq@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  0xe2a(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
lea    0xe1f(%rip),%rsi
call   1060 <sprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpu_idle_spurr>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
xor    %eax,%eax
call   1030 <get_scaled_tb@plt>
movapd %xmm0,0x10(%rsp)
lea    0xeb1(%rip),%rdi
call   1050 <get_delta_value@plt>
movapd %xmm0,(%rsp)
lea    0xe9b(%rip),%rdi
call   1050 <get_delta_value@plt>
movapd (%rsp),%xmm2
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
unpcklpd %xmm1,%xmm2
movapd 0x10(%rsp),%xmm0
unpcklpd %xmm0,%xmm0
divpd  %xmm0,%xmm2
movapd %xmm2,%xmm0
unpckhpd %xmm2,%xmm0
subsd  %xmm0,%xmm2
mulsd  0xe5b(%rip),%xmm2
movapd %xmm2,(%rsp)
xor    %eax,%eax
call   1040 <round_off_freq@plt>
movapd (%rsp),%xmm1
mulsd  %xmm1,%xmm0
divsd  0xe3e(%rip),%xmm0
addsd  %xmm1,%xmm0
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
add    $0x20,%rsp
pop    %rbx
jmp    1060 <sprintf@plt>

LLVM IR (-O0):
%struct.sysentry = type { i32 }
@.str = [6 x i8] c"spurr\00"
@.str.1 = [11 x i8] c"idle_spurr\00"
@.str.2 = [5 x i8] c"%.2f\00"
define void @get_cpu_idle_spurr(%struct.sysentry* %0, i8* %1) {
%3 = alloca %struct.sysentry*
%4 = alloca i8*
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store %struct.sysentry* %0, %struct.sysentry** %3
store i8* %1, i8** %4
%11 = call double (...) @get_scaled_tb()
store double %11, double* %5
%12 = call double @get_delta_value(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store double %12, double* %6
%13 = call double @get_delta_value(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store double %13, double* %7
%14 = load double, double* %6
%15 = load double, double* %7
%16 = fsub double %14, %15
%17 = load double, double* %5
%18 = fdiv double %16, %17
store double %18, double* %8
%19 = load double, double* %6
%20 = load double, double* %5
%21 = fdiv double %19, %20
%22 = load double, double* %8
%23 = fsub double %21, %22
store double %23, double* %9
%24 = load double, double* %9
%25 = fmul double %24, 1.000000e+02
store double %25, double* %9
%26 = call double (...) @round_off_freq()
store double %26, double* %10
%27 = load double, double* %9
%28 = load double, double* %10
%29 = fmul double %27, %28
%30 = fdiv double %29, 1.000000e+02
%31 = load double, double* %9
%32 = fadd double %31, %30
store double %32, double* %9
%33 = load i8*, i8** %4
%34 = load double, double* %9
%35 = call i32 @sprintf(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %34)
ret void
}

LLVM IR (-O2):
%struct.sysentry = type { i32 }
@.str = [6 x i8] c"spurr\00"
@.str.1 = [11 x i8] c"idle_spurr\00"
@.str.2 = [5 x i8] c"%.2f\00"
define void @get_cpu_idle_spurr(%struct.sysentry* nocapture readnone %0, i8* nocapture writeonly %1) {
%3 = tail call double (...) @get_scaled_tb()
%4 = tail call double @get_delta_value(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = tail call double @get_delta_value(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%6 = fsub double %4, %5
%7 = insertelement <2 x double> poison, double %4, i64 0
%8 = insertelement <2 x double> %7, double %6, i64 1
%9 = insertelement <2 x double> poison, double %3, i64 0
%10 = shufflevector <2 x double> %9, <2 x double> poison, <2 x i32> zeroinitializer
%11 = fdiv <2 x double> %8, %10
%12 = shufflevector <2 x double> %11, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%13 = fsub <2 x double> %11, %12
%14 = extractelement <2 x double> %13, i64 0
%15 = fmul double %14, 1.000000e+02
%16 = tail call double (...) @round_off_freq()
%17 = fmul double %16, %15
%18 = fdiv double %17, 1.000000e+02
%19 = fadd double %15, %18
%20 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %19)
ret void
}