#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 /*<<< orphan*/ printf(char *, double, double, double);
double PIDcon(double after_p, double before_p, double cmd_angle,
              double *theta_integral, double cmd_Pgain, double cmd_Igain,
              double cmd_Dgain) {
  int Derivatives = 0;
  double cmd = 0;
  double time_interval = 0.01;
  double P_cmd = 0;
  double I_cmd = 0;
  double D_cmd = 0;
  double after = after_p - cmd_angle;
  double before = before_p - cmd_angle;
  *theta_integral += after;
  P_cmd = cmd_Pgain * after;
  I_cmd = cmd_Igain * (*theta_integral) * time_interval;
  D_cmd = cmd_Dgain * (after - before) / time_interval;
  cmd = 1280000 + P_cmd + I_cmd + D_cmd;
  if (cmd < 1000000)
    cmd = 1000000;
  if (cmd > 2000000)
    cmd = 2000000;
  printf("%.4f,%.4f,%.4f\n", P_cmd, I_cmd, D_cmd);
  return cmd / 100000;
}


x86 assembly (clang, -O0):
<PIDcon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  %xmm4,-0x30(%rbp)
movsd  %xmm5,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xebc(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x70(%rbp),%xmm0
mov    -0x20(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mulsd  (%rax),%xmm0
mulsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm1
subsd  -0x78(%rbp),%xmm1
mulsd  %xmm1,%xmm0
divsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  0xe1d(%rip),%xmm0
addsd  -0x58(%rbp),%xmm0
addsd  -0x60(%rbp),%xmm0
addsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xdf9(%rip),%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    121f <PIDcon+0x10f>
movsd  0xde6(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  0xdec(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1243 <PIDcon+0x133>
movsd  0xdda(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm2
lea    0xdcf(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x48(%rbp),%xmm0
movsd  0xdb5(%rip),%xmm1
divsd  %xmm1,%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PIDcon>:
push   %rax
movapd %xmm1,%xmm7
movapd %xmm0,%xmm6
subsd  %xmm2,%xmm6
subsd  %xmm2,%xmm7
movsd  (%rdi),%xmm1
addsd  %xmm6,%xmm1
movsd  %xmm1,(%rdi)
mulsd  %xmm6,%xmm3
mulsd  %xmm4,%xmm1
movsd  0xec3(%rip),%xmm0
mulsd  %xmm0,%xmm1
subsd  %xmm7,%xmm6
mulsd  %xmm5,%xmm6
divsd  %xmm0,%xmm6
movsd  0xeb3(%rip),%xmm0
addsd  %xmm3,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm6,%xmm0
movsd  0xea7(%rip),%xmm2
maxsd  %xmm0,%xmm2
movsd  0xea3(%rip),%xmm0
minsd  %xmm2,%xmm0
movsd  %xmm0,(%rsp)
lea    0xea3(%rip),%rdi
movapd %xmm3,%xmm0
movapd %xmm6,%xmm2
call   1030 <printf@plt>
movsd  (%rsp),%xmm0
divsd  0xe81(%rip),%xmm0
pop    %rax
ret

LLVM IR (-O0):
@.str = [16 x i8] c"%.4f,%.4f,%.4f\0A\00"
define double @PIDcon(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 i32
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca double
%22 = 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 i32 0, i32* %15
store double 0.000000e+00, double* %16
store double 1.000000e-02, double* %17
store double 0.000000e+00, double* %18
store double 0.000000e+00, double* %19
store double 0.000000e+00, double* %20
%23 = load double, double* %8
%24 = load double, double* %10
%25 = fsub double %23, %24
store double %25, double* %21
%26 = load double, double* %9
%27 = load double, double* %10
%28 = fsub double %26, %27
store double %28, double* %22
%29 = load double, double* %21
%30 = load double*, double** %11
%31 = load double, double* %30
%32 = fadd double %31, %29
store double %32, double* %30
%33 = load double, double* %12
%34 = load double, double* %21
%35 = fmul double %33, %34
store double %35, double* %18
%36 = load double, double* %13
%37 = load double*, double** %11
%38 = load double, double* %37
%39 = fmul double %36, %38
%40 = load double, double* %17
%41 = fmul double %39, %40
store double %41, double* %19
%42 = load double, double* %14
%43 = load double, double* %21
%44 = load double, double* %22
%45 = fsub double %43, %44
%46 = fmul double %42, %45
%47 = load double, double* %17
%48 = fdiv double %46, %47
store double %48, double* %20
%49 = load double, double* %18
%50 = fadd double 1.280000e+06, %49
%51 = load double, double* %19
%52 = fadd double %50, %51
%53 = load double, double* %20
%54 = fadd double %52, %53
store double %54, double* %16
%55 = load double, double* %16
%56 = fcmp olt double %55, 1.000000e+06
br i1 %56, label %57, label %58
57: ; preds = %7
store double 1.000000e+06, double* %16
br label %58
58: ; preds = %57, %7
%59 = load double, double* %16
%60 = fcmp ogt double %59, 2.000000e+06
br i1 %60, label %61, label %62
61: ; preds = %58
store double 2.000000e+06, double* %16
br label %62
62: ; preds = %61, %58
%63 = load double, double* %18
%64 = load double, double* %19
%65 = load double, double* %20
%66 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), double %63, double %64, double %65)
%67 = load double, double* %16
%68 = fdiv double %67, 1.000000e+05
ret double %68
}

LLVM IR (-O2):
@.str = [16 x i8] c"%.4f,%.4f,%.4f\0A\00"
define double @PIDcon(double %0, double %1, double %2, double* nocapture %3, double %4, double %5, double %6) {
%8 = fsub double %0, %2
%9 = fsub double %1, %2
%10 = load double, double* %3
%11 = fadd double %8, %10
store double %11, double* %3
%12 = fmul double %8, %4
%13 = fmul double %11, %5
%14 = fmul double %13, 1.000000e-02
%15 = fsub double %8, %9
%16 = fmul double %15, %6
%17 = fdiv double %16, 1.000000e-02
%18 = fadd double %12, 1.280000e+06
%19 = fadd double %18, %14
%20 = fadd double %17, %19
%21 = fcmp olt double %20, 1.000000e+06
%22 = select i1 %21, double 1.000000e+06, double %20
%23 = fcmp ogt double %22, 2.000000e+06
%24 = select i1 %23, double 2.000000e+06, double %22
%25 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), double %12, double %14, double %17)
%26 = fdiv double %24, 1.000000e+05
ret double %26
}