double PIDcontroller(double TarVal, double NowVal, double *ValPrevErr,
                     double *ValDevSum, double Kp, double Ki, double Kd) {
  double ValCurrErr = 0.0;
  double ValPCtrl = 0.0;
  double ValICtrl = 0.0;
  double ValDCtrl = 0.0;
  double ResultVal = 0.0;
  ValCurrErr = TarVal - NowVal;
  ValPCtrl = Kp * ValCurrErr;
  *ValDevSum += ValCurrErr * 0.005;
  ValICtrl = Ki * *ValDevSum;
  ValDCtrl = Kd * ((ValCurrErr - *ValPrevErr) * 200);
  ResultVal = (ValPCtrl + ValICtrl + ValDCtrl);
  *ValPrevErr = ValCurrErr;
  return ResultVal;
}


x86 assembly (clang, -O0):
<PIDcontroller>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
movsd  %xmm3,-0x30(%rbp)
movsd  %xmm4,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm1
movsd  0xe88(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
movsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
mov    -0x18(%rbp),%rax
subsd  (%rax),%xmm1
movsd  0xe48(%rip),%xmm2
mulsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x48(%rbp),%xmm0
addsd  -0x50(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x60(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<PIDcontroller>:
subsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm2
movsd  0xef0(%rip),%xmm5
mulsd  %xmm0,%xmm5
addsd  (%rsi),%xmm5
movsd  %xmm5,(%rsi)
mulsd  %xmm3,%xmm5
movapd %xmm0,%xmm1
subsd  (%rdi),%xmm1
mulsd  0xed8(%rip),%xmm1
addsd  %xmm2,%xmm5
mulsd  %xmm4,%xmm1
addsd  %xmm5,%xmm1
movsd  %xmm0,(%rdi)
movapd %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @PIDcontroller(double %0, double %1, double* %2, double* %3, double %4, double %5, double %6) {
%8 = alloca double
%9 = alloca double
%10 = alloca double*
%11 = alloca double*
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
store double %0, double* %8
store double %1, double* %9
store double* %2, double** %10
store double* %3, double** %11
store double %4, double* %12
store double %5, double* %13
store double %6, double* %14
store double 0.000000e+00, double* %15
store double 0.000000e+00, double* %16
store double 0.000000e+00, double* %17
store double 0.000000e+00, double* %18
store double 0.000000e+00, double* %19
%20 = load double, double* %8
%21 = load double, double* %9
%22 = fsub double %20, %21
store double %22, double* %15
%23 = load double, double* %12
%24 = load double, double* %15
%25 = fmul double %23, %24
store double %25, double* %16
%26 = load double, double* %15
%27 = load double*, double** %11
%28 = load double, double* %27
%29 = call double @llvm.fmuladd.f64(double %26, double 5.000000e-03, double %28)
store double %29, double* %27
%30 = load double, double* %13
%31 = load double*, double** %11
%32 = load double, double* %31
%33 = fmul double %30, %32
store double %33, double* %17
%34 = load double, double* %14
%35 = load double, double* %15
%36 = load double*, double** %10
%37 = load double, double* %36
%38 = fsub double %35, %37
%39 = fmul double %38, 2.000000e+02
%40 = fmul double %34, %39
store double %40, double* %18
%41 = load double, double* %16
%42 = load double, double* %17
%43 = fadd double %41, %42
%44 = load double, double* %18
%45 = fadd double %43, %44
store double %45, double* %19
%46 = load double, double* %15
%47 = load double*, double** %10
store double %46, double* %47
%48 = load double, double* %19
ret double %48
}

LLVM IR (-O2):
define double @PIDcontroller(double %0, double %1, double* nocapture %2, double* nocapture %3, double %4, double %5, double %6) {
%8 = fsub double %0, %1
%9 = fmul double %8, %4
%10 = load double, double* %3
%11 = tail call double @llvm.fmuladd.f64(double %8, double 5.000000e-03, double %10)
store double %11, double* %3
%12 = fmul double %11, %5
%13 = load double, double* %2
%14 = fsub double %8, %13
%15 = fmul double %14, 2.000000e+02
%16 = fmul double %15, %6
%17 = fadd double %9, %12
%18 = fadd double %17, %16
store double %8, double* %2
ret double %18
}