#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_util_spurr(struct sysentry *unused_se, char *buf) {
  double delta_tb, delta_spurr, delta_idle_spurr;
  double physc, 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;
  physc *= 100.00;
  rfreq = round_off_freq();
  physc += ((physc * rfreq) / 100);
  sprintf(buf, "%.2f", physc);
}


x86 assembly (clang, -O0):
<get_cpu_util_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  0xe66(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1040 <round_off_freq@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  0xe3e(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
movsd  -0x30(%rbp),%xmm0
lea    0xe33(%rip),%rsi
call   1060 <sprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpu_util_spurr>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
xor    %eax,%eax
call   1030 <get_scaled_tb@plt>
movsd  %xmm0,0x8(%rsp)
lea    0xeb1(%rip),%rdi
call   1050 <get_delta_value@plt>
movsd  %xmm0,(%rsp)
lea    0xe9b(%rip),%rdi
call   1050 <get_delta_value@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
divsd  0x8(%rsp),%xmm1
mulsd  0xe77(%rip),%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1040 <round_off_freq@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm0
divsd  0xe5a(%rip),%xmm0
addsd  %xmm1,%xmm0
lea    0xe62(%rip),%rsi
mov    %rbx,%rdi
add    $0x10,%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_util_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
store %struct.sysentry* %0, %struct.sysentry** %3
store i8* %1, i8** %4
%10 = call double (...) @get_scaled_tb()
store double %10, double* %5
%11 = call double @get_delta_value(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store double %11, double* %6
%12 = call double @get_delta_value(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store double %12, double* %7
%13 = load double, double* %6
%14 = load double, double* %7
%15 = fsub double %13, %14
%16 = load double, double* %5
%17 = fdiv double %15, %16
store double %17, double* %8
%18 = load double, double* %8
%19 = fmul double %18, 1.000000e+02
store double %19, double* %8
%20 = call double (...) @round_off_freq()
store double %20, double* %9
%21 = load double, double* %8
%22 = load double, double* %9
%23 = fmul double %21, %22
%24 = fdiv double %23, 1.000000e+02
%25 = load double, double* %8
%26 = fadd double %25, %24
store double %26, double* %8
%27 = load i8*, i8** %4
%28 = load double, double* %8
%29 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %28)
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_util_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 = fdiv double %6, %3
%8 = fmul double %7, 1.000000e+02
%9 = tail call double (...) @round_off_freq()
%10 = fmul double %9, %8
%11 = fdiv double %10, 1.000000e+02
%12 = fadd double %8, %11
%13 = 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 %12)
ret void
}