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

/* Variables and functions */
int abs(float);
float PID(float setpoint, float ProcessValue) {
  static float init_error = 0;
  static float integral = 0;
  float error;
  float derivative;
  float PIDoutput;
  error = setpoint - ProcessValue;
  if (abs(error) > 5) {
    integral = integral + error * 0.001;
  }
  derivative = (error - init_error) / 0.001;
  PIDoutput = 0.1 * error + 0.0 * integral + 0.1 * derivative;
  if (PIDoutput < -100) {
    PIDoutput = -100;
  } else if (PIDoutput > 100) {
    PIDoutput = 100;
  }
  init_error = error;
  return PIDoutput;
}


x86 assembly (clang, -O0):
<PID>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <abs@plt>
cmp    $0x5,%eax
jle    1175 <PID+0x65>
movss  0x2ee4(%rip),%xmm0
cvtss2sd %xmm0,%xmm1
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe9f(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x2ebb(%rip)
movss  -0xc(%rbp),%xmm0
subss  0x2eaa(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe72(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movss  0x2e84(%rip),%xmm0
cvtss2sd %xmm0,%xmm2
xorps  %xmm0,%xmm0
mulsd  %xmm2,%xmm0
movsd  0xe49(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe30(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  0xe1f(%rip),%xmm0
ucomiss -0x14(%rbp),%xmm0
jbe    120d <PID+0xfd>
movss  0xe0d(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    1235 <PID+0x125>
movss  -0x14(%rbp),%xmm0
movss  0xdfa(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    1230 <PID+0x120>
movss  0xde9(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    1235 <PID+0x125>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,0x2dea(%rip)
movss  -0x14(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PID>:
push   %rax
subss  %xmm1,%xmm0
movss  %xmm0,0x4(%rsp)
call   1030 <abs@plt>
movss  0x2f08(%rip),%xmm1
cmp    $0x5,%eax
jle    115f <PID+0x4f>
cvtss2sd %xmm1,%xmm1
movss  0x4(%rsp),%xmm4
xorps  %xmm0,%xmm0
cvtss2sd %xmm4,%xmm0
movsd  0xeba(%rip),%xmm2
mulsd  %xmm0,%xmm2
addsd  %xmm1,%xmm2
xorps  %xmm1,%xmm1
cvtsd2ss %xmm2,%xmm1
movss  %xmm1,0x2ed3(%rip)
jmp    116c <PID+0x5c>
movss  0x4(%rsp),%xmm4
xorps  %xmm0,%xmm0
cvtss2sd %xmm4,%xmm0
movaps %xmm4,%xmm2
subss  0x2eb5(%rip),%xmm2
cvtss2sd %xmm2,%xmm2
divsd  0xe7d(%rip),%xmm2
cvtsd2ss %xmm2,%xmm2
cvtss2sd %xmm1,%xmm1
xorpd  %xmm3,%xmm3
mulsd  %xmm1,%xmm3
movsd  0xe6d(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm3,%xmm0
cvtss2sd %xmm2,%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
xorps  %xmm1,%xmm1
cvtsd2ss %xmm2,%xmm1
movss  0xe52(%rip),%xmm0
ucomiss %xmm1,%xmm0
ja     11d7 <PID+0xc7>
ucomiss 0xe4a(%rip),%xmm1
movaps %xmm1,%xmm0
jbe    11d7 <PID+0xc7>
movss  0xe3d(%rip),%xmm0
movss  %xmm4,0x2e4d(%rip)
pop    %rax
ret

LLVM IR (-O0):
@PID.init_error = internal global float 0.000000e+00
@PID.integral = internal global float 0.000000e+00
define float @PID(float %0, float %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
store float %0, float* %3
store float %1, float* %4
%8 = load float, float* %3
%9 = load float, float* %4
%10 = fsub float %8, %9
store float %10, float* %5
%11 = load float, float* %5
%12 = call i32 @abs(float %11)
%13 = icmp sgt i32 %12, 5
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load float, float* @PID.integral
%16 = fpext float %15 to double
%17 = load float, float* %5
%18 = fpext float %17 to double
%19 = call double @llvm.fmuladd.f64(double %18, double 1.000000e-03, double %16)
%20 = fptrunc double %19 to float
store float %20, float* @PID.integral
br label %21
21: ; preds = %14, %2
%22 = load float, float* %5
%23 = load float, float* @PID.init_error
%24 = fsub float %22, %23
%25 = fpext float %24 to double
%26 = fdiv double %25, 1.000000e-03
%27 = fptrunc double %26 to float
store float %27, float* %6
%28 = load float, float* %5
%29 = fpext float %28 to double
%30 = load float, float* @PID.integral
%31 = fpext float %30 to double
%32 = fmul double 0.000000e+00, %31
%33 = call double @llvm.fmuladd.f64(double 1.000000e-01, double %29, double %32)
%34 = load float, float* %6
%35 = fpext float %34 to double
%36 = call double @llvm.fmuladd.f64(double 1.000000e-01, double %35, double %33)
%37 = fptrunc double %36 to float
store float %37, float* %7
%38 = load float, float* %7
%39 = fcmp olt float %38, -1.000000e+02
br i1 %39, label %40, label %41
40: ; preds = %21
store float -1.000000e+02, float* %7
br label %46
41: ; preds = %21
%42 = load float, float* %7
%43 = fcmp ogt float %42, 1.000000e+02
br i1 %43, label %44, label %45
44: ; preds = %41
store float 1.000000e+02, float* %7
br label %45
45: ; preds = %44, %41
br label %46
46: ; preds = %45, %40
%47 = load float, float* %5
store float %47, float* @PID.init_error
%48 = load float, float* %7
ret float %48
}

LLVM IR (-O2):
@PID.init_error = internal unnamed_addr global float 0.000000e+00
@PID.integral = internal unnamed_addr global float 0.000000e+00
define float @PID(float %0, float %1) {
%3 = fsub float %0, %1
%4 = tail call i32 @abs(float %3)
%5 = icmp sgt i32 %4, 5
%6 = load float, float* @PID.integral
br i1 %5, label %9, label %7
7: ; preds = %2
%8 = fpext float %3 to double
br label %14
9: ; preds = %2
%10 = fpext float %6 to double
%11 = fpext float %3 to double
%12 = tail call double @llvm.fmuladd.f64(double %11, double 1.000000e-03, double %10)
%13 = fptrunc double %12 to float
store float %13, float* @PID.integral
br label %14
14: ; preds = %7, %9
%15 = phi double [ %8, %7 ], [ %11, %9 ]
%16 = phi float [ %6, %7 ], [ %13, %9 ]
%17 = load float, float* @PID.init_error
%18 = fsub float %3, %17
%19 = fpext float %18 to double
%20 = fdiv double %19, 1.000000e-03
%21 = fptrunc double %20 to float
%22 = fpext float %16 to double
%23 = fmul double %22, 0.000000e+00
%24 = tail call double @llvm.fmuladd.f64(double %15, double 1.000000e-01, double %23)
%25 = fpext float %21 to double
%26 = tail call double @llvm.fmuladd.f64(double %25, double 1.000000e-01, double %24)
%27 = fptrunc double %26 to float
%28 = fcmp olt float %27, -1.000000e+02
br i1 %28, label %32, label %29
29: ; preds = %14
%30 = fcmp ogt float %27, 1.000000e+02
br i1 %30, label %31, label %32
31: ; preds = %29
br label %32
32: ; preds = %14, %29, %31
%33 = phi float [ 1.000000e+02, %31 ], [ %27, %29 ], [ -1.000000e+02, %14 ]
store float %3, float* @PID.init_error
ret float %33
}