; LLVM IR from segway-robotics/loomo-algodev :: algo_app/src/main/jni/app_follow/PID.ll (ZN7PIDImpl9calculateEdd)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%class.PIDImpl = type { double, double, double, double, double, double, double, double }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN7PIDImpl9calculateEdd(ptr noundef nonnull align 8 dereferenceable(64) %0, double noundef %1, double noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  store double %2, ptr %6, align 8, !tbaa !9
  %13 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %14 = load double, ptr %5, align 8, !tbaa !9
  %15 = load double, ptr %6, align 8, !tbaa !9
  %16 = fsub double %14, %15
  store double %16, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %17 = getelementptr inbounds %class.PIDImpl, ptr %13, i32 0, i32 3
  %18 = load double, ptr %17, align 8, !tbaa !11
  %19 = load double, ptr %7, align 8, !tbaa !9
  %20 = fmul double %18, %19
  store double %20, ptr %8, align 8, !tbaa !9
  %21 = load double, ptr %7, align 8, !tbaa !9
  %22 = getelementptr inbounds %class.PIDImpl, ptr %13, i32 0, i32 0
  %23 = load double, ptr %22, align 8, !tbaa !13
  %24 = getelementptr inbounds %class.PIDImpl, ptr %13, i32 0, i32 7
  %25 = load double, ptr %24, align 8, !tbaa !14
  %26 = call double @llvm.fmuladd.f64(double %21, double %23, double %25)
  store double %26, ptr %24, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %27 = getelementptr inbounds %class.PIDImpl, ptr %13, i32 0, i32 5
  %28 = load double, ptr %27, align 8, !tbaa !15
  %29 = getelementptr inbounds %class.PIDImpl, ptr %13, i32 0, i32 7
  %30 = load double, ptr %29, align 8, !tbaa !14
  %31 = fmul double %28, %30
  store double %31, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %32 = load double, ptr %7, align 8, !tbaa !9
  %33 = getelementptr inbounds %class.PIDImpl, ptr %13, i32 0, i32 6
  %34 = load double, ptr %33, align 8, !tbaa !16
  %35 = fsub double %32, %34
  %36 = getelementptr inbounds %class.PIDImpl, ptr %13, i32 0, i32 0
  %37 = load double, ptr %36, align 8, !tbaa !13
  %38 = fdiv double %35, %37
  store double %38, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %39 = getelementptr inbounds %class.PIDImpl, ptr %13, i32 0, i32 4
  %40 = load double, ptr %39, align 8, !tbaa !17
  %41 = load double, ptr %10, align 8, !tbaa !9
  %42 = fmul double %40, %41
  store double %42, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %43 = load double, ptr %8, align 8, !tbaa !9
  %44 = load double, ptr %9, align 8, !tbaa !9
  %45 = fadd double %43, %44
  %46 = load double, ptr %11, align 8, !tbaa !9
  %47 = fadd double %45, %46
  store double %47, ptr %12, align 8, !tbaa !9
  %48 = load double, ptr %12, align 8, !tbaa !9
  %49 = getelementptr inbounds %class.PIDImpl, ptr %13, i32 0, i32 1
  %50 = load double, ptr %49, align 8, !tbaa !18
  %51 = fcmp ogt double %48, %50
  br i1 %51, label %52, label %55

52:                                               ; preds = %3
  %53 = getelementptr inbounds %class.PIDImpl, ptr %13, i32 0, i32 1
  %54 = load double, ptr %53, align 8, !tbaa !18
  store double %54, ptr %12, align 8, !tbaa !9
  br label %64

55:                                               ; preds = %3
  %56 = load double, ptr %12, align 8, !tbaa !9
  %57 = getelementptr inbounds %class.PIDImpl, ptr %13, i32 0, i32 2
  %58 = load double, ptr %57, align 8, !tbaa !19
  %59 = fcmp olt double %56, %58
  br i1 %59, label %60, label %63

60:                                               ; preds = %55
  %61 = getelementptr inbounds %class.PIDImpl, ptr %13, i32 0, i32 2
  %62 = load double, ptr %61, align 8, !tbaa !19
  store double %62, ptr %12, align 8, !tbaa !9
  br label %63

63:                                               ; preds = %60, %55
  br label %64

64:                                               ; preds = %63, %52
  %65 = load double, ptr %7, align 8, !tbaa !9
  %66 = getelementptr inbounds %class.PIDImpl, ptr %13, i32 0, i32 6
  store double %65, ptr %66, align 8, !tbaa !16
  %67 = load double, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret double %67
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"_ZTS7PIDImpl", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !10, i64 56}
!15 = !{!12, !10, i64 40}
!16 = !{!12, !10, i64 48}
!17 = !{!12, !10, i64 32}
!18 = !{!12, !10, i64 8}
!19 = !{!12, !10, i64 16}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local noundef double @_ZN7PIDImpl9calculateEdd(ptr nocapture noundef nonnull align 8 dereferenceable(64) %0, double noundef %1, double noundef %2) local_unnamed_addr #0 align 2 {
  %4 = fsub double %1, %2
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load double, ptr %0, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 56
  %8 = load double, ptr %7, align 8, !tbaa !10
  %9 = tail call double @llvm.fmuladd.f64(double %4, double %6, double %8)
  store double %9, ptr %7, align 8, !tbaa !10
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  %11 = load double, ptr %10, align 8, !tbaa !11
  %12 = fmul double %9, %11
  %13 = getelementptr inbounds i8, ptr %0, i64 48
  %14 = load double, ptr %13, align 8, !tbaa !12
  %15 = fsub double %4, %14
  %16 = fdiv double %15, %6
  %17 = load <2 x double>, ptr %5, align 8, !tbaa !13
  %18 = insertelement <2 x double> poison, double %4, i64 0
  %19 = insertelement <2 x double> %18, double %16, i64 1
  %20 = fmul <2 x double> %19, %17
  %21 = extractelement <2 x double> %20, i64 0
  %22 = fadd double %21, %12
  %23 = extractelement <2 x double> %20, i64 1
  %24 = fadd double %22, %23
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  %26 = load double, ptr %25, align 8, !tbaa !14
  %27 = fcmp ogt double %24, %26
  br i1 %27, label %33, label %28

28:                                               ; preds = %3
  %29 = getelementptr inbounds i8, ptr %0, i64 16
  %30 = load double, ptr %29, align 8, !tbaa !15
  %31 = fcmp olt double %24, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %28
  br label %33

33:                                               ; preds = %3, %28, %32
  %.0 = phi double [ %30, %32 ], [ %24, %28 ], [ %26, %3 ]
  store double %4, ptr %13, align 8, !tbaa !12
  ret double %.0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !7, i64 0}
!6 = !{!"_ZTS7PIDImpl", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 56}
!11 = !{!6, !7, i64 40}
!12 = !{!6, !7, i64 48}
!13 = !{!7, !7, i64 0}
!14 = !{!6, !7, i64 8}
!15 = !{!6, !7, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass