; LLVM IR from BigdogManLuo/DSPLibrary :: DSPTools/PID_Controller (pid)

; 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"

%struct.PID = type { float, float, float, float, float, float, float }

; Function Attrs: nounwind uwtable
define dso_local float @PIDCalc(ptr noundef %0, float noundef %1, float noundef %2, float noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store float %1, ptr %6, align 4, !tbaa !9
  store float %2, ptr %7, align 4, !tbaa !9
  store float %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %11 = load float, ptr %7, align 4, !tbaa !9
  %12 = load float, ptr %6, align 4, !tbaa !9
  %13 = fsub float %11, %12
  store float %13, ptr %10, align 4, !tbaa !9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.PID, ptr %14, i32 0, i32 4
  %16 = load float, ptr %15, align 4, !tbaa !11
  %17 = load float, ptr %8, align 4, !tbaa !9
  %18 = fcmp ogt float %16, %17
  br i1 %18, label %19, label %23

19:                                               ; preds = %4
  %20 = load float, ptr %8, align 4, !tbaa !9
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.PID, ptr %21, i32 0, i32 4
  store float %20, ptr %22, align 4, !tbaa !11
  br label %32

23:                                               ; preds = %4
  %24 = load float, ptr %10, align 4, !tbaa !9
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.PID, ptr %25, i32 0, i32 6
  %27 = load float, ptr %26, align 4, !tbaa !13
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.PID, ptr %28, i32 0, i32 4
  %30 = load float, ptr %29, align 4, !tbaa !11
  %31 = call float @llvm.fmuladd.f32(float %24, float %27, float %30)
  store float %31, ptr %29, align 4, !tbaa !11
  br label %32

32:                                               ; preds = %23, %19
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.PID, ptr %33, i32 0, i32 3
  %35 = load float, ptr %34, align 4, !tbaa !14
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.PID, ptr %36, i32 0, i32 5
  %38 = load float, ptr %37, align 4, !tbaa !15
  %39 = fsub float %35, %38
  store float %39, ptr %9, align 4, !tbaa !9
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.PID, ptr %40, i32 0, i32 3
  %42 = load float, ptr %41, align 4, !tbaa !14
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.PID, ptr %43, i32 0, i32 5
  store float %42, ptr %44, align 4, !tbaa !15
  %45 = load float, ptr %10, align 4, !tbaa !9
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.PID, ptr %46, i32 0, i32 3
  store float %45, ptr %47, align 4, !tbaa !14
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.PID, ptr %48, i32 0, i32 0
  %50 = load float, ptr %49, align 4, !tbaa !16
  %51 = load float, ptr %10, align 4, !tbaa !9
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.PID, ptr %52, i32 0, i32 1
  %54 = load float, ptr %53, align 4, !tbaa !17
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.PID, ptr %55, i32 0, i32 4
  %57 = load float, ptr %56, align 4, !tbaa !11
  %58 = fmul float %54, %57
  %59 = call float @llvm.fmuladd.f32(float %50, float %51, float %58)
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.PID, ptr %60, i32 0, i32 2
  %62 = load float, ptr %61, align 4, !tbaa !18
  %63 = load float, ptr %9, align 4, !tbaa !9
  %64 = call float @llvm.fmuladd.f32(float %62, float %63, float %59)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret float %64
}

; 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 float @llvm.fmuladd.f32(float, float, float) #2

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

attributes #0 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"PID", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24}
!13 = !{!12, !10, i64 24}
!14 = !{!12, !10, i64 12}
!15 = !{!12, !10, i64 20}
!16 = !{!12, !10, i64 0}
!17 = !{!12, !10, i64 4}
!18 = !{!12, !10, i64 8}


; 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 float @PIDCalc(ptr nocapture noundef %0, float noundef %1, float noundef %2, float noundef %3) local_unnamed_addr #0 {
  %5 = fsub float %2, %1
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load float, ptr %6, align 4, !tbaa !5
  %8 = fcmp ogt float %7, %3
  br i1 %8, label %13, label %9

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load float, ptr %10, align 4, !tbaa !10
  %12 = tail call float @llvm.fmuladd.f32(float %5, float %11, float %7)
  br label %13

13:                                               ; preds = %4, %9
  %storemerge = phi float [ %12, %9 ], [ %3, %4 ]
  store float %storemerge, ptr %6, align 4, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %0, i64 12
  %15 = load float, ptr %14, align 4, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %0, i64 20
  %17 = load float, ptr %16, align 4, !tbaa !12
  %18 = fsub float %15, %17
  store float %15, ptr %16, align 4, !tbaa !12
  store float %5, ptr %14, align 4, !tbaa !11
  %19 = load float, ptr %0, align 4, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %0, i64 4
  %21 = load float, ptr %20, align 4, !tbaa !14
  %22 = fmul float %storemerge, %21
  %23 = tail call float @llvm.fmuladd.f32(float %19, float %5, float %22)
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  %25 = load float, ptr %24, align 4, !tbaa !15
  %26 = tail call float @llvm.fmuladd.f32(float %25, float %18, float %23)
  ret float %26
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #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 16}
!6 = !{!"PID", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 24}
!11 = !{!6, !7, i64 12}
!12 = !{!6, !7, i64 20}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !7, i64 4}
!15 = !{!6, !7, i64 8}


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