#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();
int /*<<< orphan*/ sprintf(char *, char *, double);
void get_cpu_idle_purr(struct sysentry *unused_se, char *buf) {
  double delta_tb, delta_purr, delta_idle_purr;
  double physc, idle;
  delta_tb = get_scaled_tb();
  delta_purr = get_delta_value("purr");
  delta_idle_purr = get_delta_value("idle_purr");
  physc = (delta_purr - delta_idle_purr) / delta_tb;
  idle = (delta_purr / delta_tb) - physc;
  idle *= 100.00;
  sprintf(buf, "%.2f", idle);
}


x86 assembly (clang, -O0):
<get_cpu_idle_purr>:
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    0xeba(%rip),%rdi
call   1040 <get_delta_value@plt>
movsd  %xmm0,-0x20(%rbp)
lea    0xea4(%rip),%rdi
call   1040 <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  0xe62(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
lea    0xe5a(%rip),%rsi
call   1050 <sprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpu_idle_purr>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
xor    %eax,%eax
call   1030 <get_scaled_tb@plt>
movapd %xmm0,0x10(%rsp)
lea    0xec1(%rip),%rdi
call   1040 <get_delta_value@plt>
movapd %xmm0,(%rsp)
lea    0xeab(%rip),%rdi
call   1040 <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  0xe6b(%rip),%xmm2
movapd %xmm2,%xmm0
lea    0xe72(%rip),%rsi
mov    %rbx,%rdi
add    $0x20,%rsp
pop    %rbx
jmp    1050 <sprintf@plt>

LLVM IR (-O0):
%struct.sysentry = type { i32 }
@.str = [5 x i8] c"purr\00"
@.str.1 = [10 x i8] c"idle_purr\00"
@.str.2 = [5 x i8] c"%.2f\00"
define void @get_cpu_idle_purr(%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 ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store double %11, double* %6
%12 = call double @get_delta_value(i8* getelementptr inbounds ([10 x i8], [10 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* %6
%19 = load double, double* %5
%20 = fdiv double %18, %19
%21 = load double, double* %8
%22 = fsub double %20, %21
store double %22, double* %9
%23 = load double, double* %9
%24 = fmul double %23, 1.000000e+02
store double %24, double* %9
%25 = load i8*, i8** %4
%26 = load double, double* %9
%27 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %26)
ret void
}

LLVM IR (-O2):
%struct.sysentry = type { i32 }
@.str = [5 x i8] c"purr\00"
@.str.1 = [10 x i8] c"idle_purr\00"
@.str.2 = [5 x i8] c"%.2f\00"
define void @get_cpu_idle_purr(%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 ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = tail call double @get_delta_value(i8* getelementptr inbounds ([10 x i8], [10 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 i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %15)
ret void
}