; LLVM IR from pms67/HadesFCS :: Firmware/F4/HadesF4Testbed_RTOS/Core/Src (KalmanAHRSQuat)

; 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.EKF = type { [4 x float], [4 x [4 x float]], float, float, float, float, float, float, float }

; Function Attrs: nounwind uwtable
define dso_local void @EKF_Init(ptr noundef %0, float noundef %1, float noundef %2, float noundef %3, float noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store float %1, ptr %7, align 4, !tbaa !9
  store float %2, ptr %8, align 4, !tbaa !9
  store float %3, ptr %9, align 4, !tbaa !9
  store float %4, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %13

13:                                               ; preds = %53, %5
  %14 = load i32, ptr %11, align 4, !tbaa !11
  %15 = icmp slt i32 %14, 4
  br i1 %15, label %16, label %56

16:                                               ; preds = %13
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.EKF, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %11, align 4, !tbaa !11
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [4 x float], ptr %18, i64 0, i64 %20
  store float 0.000000e+00, ptr %21, align 4, !tbaa !9
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %22

22:                                               ; preds = %49, %16
  %23 = load i32, ptr %12, align 4, !tbaa !11
  %24 = icmp slt i32 %23, 4
  br i1 %24, label %25, label %52

25:                                               ; preds = %22
  %26 = load i32, ptr %11, align 4, !tbaa !11
  %27 = load i32, ptr %12, align 4, !tbaa !11
  %28 = icmp eq i32 %26, %27
  br i1 %28, label %29, label %39

29:                                               ; preds = %25
  %30 = load float, ptr %7, align 4, !tbaa !9
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.EKF, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %11, align 4, !tbaa !11
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [4 x [4 x float]], ptr %32, i64 0, i64 %34
  %36 = load i32, ptr %12, align 4, !tbaa !11
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [4 x float], ptr %35, i64 0, i64 %37
  store float %30, ptr %38, align 4, !tbaa !9
  br label %48

39:                                               ; preds = %25
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.EKF, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %11, align 4, !tbaa !11
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [4 x [4 x float]], ptr %41, i64 0, i64 %43
  %45 = load i32, ptr %12, align 4, !tbaa !11
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [4 x float], ptr %44, i64 0, i64 %46
  store float 0.000000e+00, ptr %47, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %39, %29
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %12, align 4, !tbaa !11
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %12, align 4, !tbaa !11
  br label %22, !llvm.loop !13

52:                                               ; preds = %22
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %11, align 4, !tbaa !11
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %11, align 4, !tbaa !11
  br label %13, !llvm.loop !15

56:                                               ; preds = %13
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.EKF, ptr %57, i32 0, i32 0
  %59 = getelementptr inbounds [4 x float], ptr %58, i64 0, i64 0
  store float 1.000000e+00, ptr %59, align 4, !tbaa !9
  %60 = load float, ptr %8, align 4, !tbaa !9
  %61 = fmul float 3.000000e+00, %60
  %62 = load float, ptr %8, align 4, !tbaa !9
  %63 = fmul float %61, %62
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.EKF, ptr %64, i32 0, i32 2
  store float %63, ptr %65, align 4, !tbaa !16
  %66 = load float, ptr %9, align 4, !tbaa !9
  %67 = load float, ptr %9, align 4, !tbaa !9
  %68 = fmul float %66, %67
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.EKF, ptr %69, i32 0, i32 3
  store float %68, ptr %70, align 4, !tbaa !18
  %71 = load float, ptr %10, align 4, !tbaa !9
  %72 = load float, ptr %10, align 4, !tbaa !9
  %73 = fmul float %71, %72
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.EKF, ptr %74, i32 0, i32 4
  store float %73, ptr %75, align 4, !tbaa !19
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.EKF, ptr %76, i32 0, i32 8
  store float 0.000000e+00, ptr %77, align 4, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  ret void
}

; 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 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 = { 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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = !{!17, !10, i64 80}
!17 = !{!"", !7, i64 0, !7, i64 16, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !10, i64 104}
!18 = !{!17, !10, i64 84}
!19 = !{!17, !10, i64 88}
!20 = !{!17, !10, i64 104}


; 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: write) uwtable
define dso_local void @EKF_Init(ptr nocapture noundef writeonly %0, float noundef %1, float noundef %2, float noundef %3, float noundef %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %6, i8 0, i64 12, i1 false), !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  store float %1, ptr %7, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 20
  %9 = getelementptr inbounds i8, ptr %0, i64 36
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %8, i8 0, i64 16, i1 false)
  store float %1, ptr %9, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  %11 = getelementptr inbounds i8, ptr %0, i64 56
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %10, i8 0, i64 16, i1 false)
  store float %1, ptr %11, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 60
  %13 = getelementptr inbounds i8, ptr %0, i64 76
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %12, i8 0, i64 16, i1 false)
  store float %1, ptr %13, align 4, !tbaa !5
  store float 1.000000e+00, ptr %0, align 4, !tbaa !5
  %14 = fmul float %2, 3.000000e+00
  %15 = fmul float %14, %2
  %16 = getelementptr inbounds i8, ptr %0, i64 80
  store float %15, ptr %16, align 4, !tbaa !9
  %17 = insertelement <2 x float> poison, float %3, i64 0
  %18 = insertelement <2 x float> %17, float %4, i64 1
  %19 = fmul <2 x float> %18, %18
  %20 = getelementptr inbounds i8, ptr %0, i64 84
  store <2 x float> %19, ptr %20, align 4, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %0, i64 104
  store float 0.000000e+00, ptr %21, align 4, !tbaa !11
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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 nounwind willreturn memory(argmem: write) }

!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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 80}
!10 = !{!"", !7, i64 0, !7, i64 16, !6, i64 80, !6, i64 84, !6, i64 88, !6, i64 92, !6, i64 96, !6, i64 100, !6, i64 104}
!11 = !{!10, !6, i64 104}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass