; LLVM IR from MRPT/mrpt :: 3rdparty/xspublic/xstypes (xsmatrix)

; 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.XsQuaternion = type { %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { double, double, double, double }

@XsMath_two = external constant double, align 8

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @XsMatrix_assign(ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @XsMatrix_destruct(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @XsMatrix_setValue(ptr noundef, i64 noundef, i64 noundef, double noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @XsMatrix_fromQuaternion(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %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
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call i32 @XsQuaternion_empty(ptr noundef %16)
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %21

19:                                               ; preds = %2
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  call void @XsMatrix_destruct(ptr noundef %20)
  store i32 1, ptr %15, align 4
  br label %173

21:                                               ; preds = %2
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.XsQuaternion, ptr %22, i32 0, i32 0
  %24 = getelementptr inbounds %struct.anon, ptr %23, i32 0, i32 0
  %25 = load double, ptr %24, align 8, !tbaa !9
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.XsQuaternion, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds %struct.anon, ptr %27, i32 0, i32 0
  %29 = load double, ptr %28, align 8, !tbaa !9
  %30 = fmul double %25, %29
  store double %30, ptr %5, align 8, !tbaa !10
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.XsQuaternion, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds %struct.anon, ptr %32, i32 0, i32 1
  %34 = load double, ptr %33, align 8, !tbaa !9
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.XsQuaternion, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds %struct.anon, ptr %36, i32 0, i32 1
  %38 = load double, ptr %37, align 8, !tbaa !9
  %39 = fmul double %34, %38
  store double %39, ptr %6, align 8, !tbaa !10
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.XsQuaternion, ptr %40, i32 0, i32 0
  %42 = getelementptr inbounds %struct.anon, ptr %41, i32 0, i32 2
  %43 = load double, ptr %42, align 8, !tbaa !9
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.XsQuaternion, ptr %44, i32 0, i32 0
  %46 = getelementptr inbounds %struct.anon, ptr %45, i32 0, i32 2
  %47 = load double, ptr %46, align 8, !tbaa !9
  %48 = fmul double %43, %47
  store double %48, ptr %7, align 8, !tbaa !10
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.XsQuaternion, ptr %49, i32 0, i32 0
  %51 = getelementptr inbounds %struct.anon, ptr %50, i32 0, i32 3
  %52 = load double, ptr %51, align 8, !tbaa !9
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.XsQuaternion, ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds %struct.anon, ptr %54, i32 0, i32 3
  %56 = load double, ptr %55, align 8, !tbaa !9
  %57 = fmul double %52, %56
  store double %57, ptr %8, align 8, !tbaa !10
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.XsQuaternion, ptr %58, i32 0, i32 0
  %60 = getelementptr inbounds %struct.anon, ptr %59, i32 0, i32 0
  %61 = load double, ptr %60, align 8, !tbaa !9
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.XsQuaternion, ptr %62, i32 0, i32 0
  %64 = getelementptr inbounds %struct.anon, ptr %63, i32 0, i32 1
  %65 = load double, ptr %64, align 8, !tbaa !9
  %66 = fmul double %61, %65
  store double %66, ptr %9, align 8, !tbaa !10
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.XsQuaternion, ptr %67, i32 0, i32 0
  %69 = getelementptr inbounds %struct.anon, ptr %68, i32 0, i32 0
  %70 = load double, ptr %69, align 8, !tbaa !9
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.XsQuaternion, ptr %71, i32 0, i32 0
  %73 = getelementptr inbounds %struct.anon, ptr %72, i32 0, i32 2
  %74 = load double, ptr %73, align 8, !tbaa !9
  %75 = fmul double %70, %74
  store double %75, ptr %10, align 8, !tbaa !10
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.XsQuaternion, ptr %76, i32 0, i32 0
  %78 = getelementptr inbounds %struct.anon, ptr %77, i32 0, i32 0
  %79 = load double, ptr %78, align 8, !tbaa !9
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.XsQuaternion, ptr %80, i32 0, i32 0
  %82 = getelementptr inbounds %struct.anon, ptr %81, i32 0, i32 3
  %83 = load double, ptr %82, align 8, !tbaa !9
  %84 = fmul double %79, %83
  store double %84, ptr %11, align 8, !tbaa !10
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.XsQuaternion, ptr %85, i32 0, i32 0
  %87 = getelementptr inbounds %struct.anon, ptr %86, i32 0, i32 1
  %88 = load double, ptr %87, align 8, !tbaa !9
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.XsQuaternion, ptr %89, i32 0, i32 0
  %91 = getelementptr inbounds %struct.anon, ptr %90, i32 0, i32 2
  %92 = load double, ptr %91, align 8, !tbaa !9
  %93 = fmul double %88, %92
  store double %93, ptr %12, align 8, !tbaa !10
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.XsQuaternion, ptr %94, i32 0, i32 0
  %96 = getelementptr inbounds %struct.anon, ptr %95, i32 0, i32 1
  %97 = load double, ptr %96, align 8, !tbaa !9
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.XsQuaternion, ptr %98, i32 0, i32 0
  %100 = getelementptr inbounds %struct.anon, ptr %99, i32 0, i32 3
  %101 = load double, ptr %100, align 8, !tbaa !9
  %102 = fmul double %97, %101
  store double %102, ptr %13, align 8, !tbaa !10
  %103 = load ptr, ptr %4, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.XsQuaternion, ptr %103, i32 0, i32 0
  %105 = getelementptr inbounds %struct.anon, ptr %104, i32 0, i32 2
  %106 = load double, ptr %105, align 8, !tbaa !9
  %107 = load ptr, ptr %4, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.XsQuaternion, ptr %107, i32 0, i32 0
  %109 = getelementptr inbounds %struct.anon, ptr %108, i32 0, i32 3
  %110 = load double, ptr %109, align 8, !tbaa !9
  %111 = fmul double %106, %110
  store double %111, ptr %14, align 8, !tbaa !10
  %112 = load ptr, ptr %3, align 8, !tbaa !5
  call void @XsMatrix_assign(ptr noundef %112, i64 noundef 3, i64 noundef 3, i64 noundef 3, ptr noundef null, i64 noundef 0)
  %113 = load ptr, ptr %3, align 8, !tbaa !5
  %114 = load double, ptr %5, align 8, !tbaa !10
  %115 = load double, ptr %6, align 8, !tbaa !10
  %116 = fadd double %114, %115
  %117 = load double, ptr %7, align 8, !tbaa !10
  %118 = fsub double %116, %117
  %119 = load double, ptr %8, align 8, !tbaa !10
  %120 = fsub double %118, %119
  call void @XsMatrix_setValue(ptr noundef %113, i64 noundef 0, i64 noundef 0, double noundef %120)
  %121 = load ptr, ptr %3, align 8, !tbaa !5
  %122 = load double, ptr %12, align 8, !tbaa !10
  %123 = load double, ptr %11, align 8, !tbaa !10
  %124 = fsub double %122, %123
  %125 = load double, ptr @XsMath_two, align 8, !tbaa !10
  %126 = fmul double %124, %125
  call void @XsMatrix_setValue(ptr noundef %121, i64 noundef 0, i64 noundef 1, double noundef %126)
  %127 = load ptr, ptr %3, align 8, !tbaa !5
  %128 = load double, ptr %13, align 8, !tbaa !10
  %129 = load double, ptr %10, align 8, !tbaa !10
  %130 = fadd double %128, %129
  %131 = load double, ptr @XsMath_two, align 8, !tbaa !10
  %132 = fmul double %130, %131
  call void @XsMatrix_setValue(ptr noundef %127, i64 noundef 0, i64 noundef 2, double noundef %132)
  %133 = load ptr, ptr %3, align 8, !tbaa !5
  %134 = load double, ptr %12, align 8, !tbaa !10
  %135 = load double, ptr %11, align 8, !tbaa !10
  %136 = fadd double %134, %135
  %137 = load double, ptr @XsMath_two, align 8, !tbaa !10
  %138 = fmul double %136, %137
  call void @XsMatrix_setValue(ptr noundef %133, i64 noundef 1, i64 noundef 0, double noundef %138)
  %139 = load ptr, ptr %3, align 8, !tbaa !5
  %140 = load double, ptr %5, align 8, !tbaa !10
  %141 = load double, ptr %6, align 8, !tbaa !10
  %142 = fsub double %140, %141
  %143 = load double, ptr %7, align 8, !tbaa !10
  %144 = load double, ptr %8, align 8, !tbaa !10
  %145 = fsub double %143, %144
  %146 = fadd double %142, %145
  call void @XsMatrix_setValue(ptr noundef %139, i64 noundef 1, i64 noundef 1, double noundef %146)
  %147 = load ptr, ptr %3, align 8, !tbaa !5
  %148 = load double, ptr %14, align 8, !tbaa !10
  %149 = load double, ptr %9, align 8, !tbaa !10
  %150 = fsub double %148, %149
  %151 = load double, ptr @XsMath_two, align 8, !tbaa !10
  %152 = fmul double %150, %151
  call void @XsMatrix_setValue(ptr noundef %147, i64 noundef 1, i64 noundef 2, double noundef %152)
  %153 = load ptr, ptr %3, align 8, !tbaa !5
  %154 = load double, ptr %13, align 8, !tbaa !10
  %155 = load double, ptr %10, align 8, !tbaa !10
  %156 = fsub double %154, %155
  %157 = load double, ptr @XsMath_two, align 8, !tbaa !10
  %158 = fmul double %156, %157
  call void @XsMatrix_setValue(ptr noundef %153, i64 noundef 2, i64 noundef 0, double noundef %158)
  %159 = load ptr, ptr %3, align 8, !tbaa !5
  %160 = load double, ptr %14, align 8, !tbaa !10
  %161 = load double, ptr %9, align 8, !tbaa !10
  %162 = fadd double %160, %161
  %163 = load double, ptr @XsMath_two, align 8, !tbaa !10
  %164 = fmul double %162, %163
  call void @XsMatrix_setValue(ptr noundef %159, i64 noundef 2, i64 noundef 1, double noundef %164)
  %165 = load ptr, ptr %3, align 8, !tbaa !5
  %166 = load double, ptr %5, align 8, !tbaa !10
  %167 = load double, ptr %6, align 8, !tbaa !10
  %168 = fsub double %166, %167
  %169 = load double, ptr %7, align 8, !tbaa !10
  %170 = fsub double %168, %169
  %171 = load double, ptr %8, align 8, !tbaa !10
  %172 = fadd double %170, %171
  call void @XsMatrix_setValue(ptr noundef %165, i64 noundef 2, i64 noundef 2, double noundef %172)
  store i32 0, ptr %15, align 4
  br label %173

173:                                              ; preds = %21, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %174 = load i32, ptr %15, align 4
  switch i32 %174, label %176 [
    i32 0, label %175
    i32 1, label %175
  ]

175:                                              ; preds = %173, %173
  ret void

176:                                              ; preds = %173
  unreachable
}

declare i32 @XsQuaternion_empty(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 #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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"double", !7, i64 0}


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

@XsMath_two = external local_unnamed_addr constant double, align 8

; Function Attrs: nounwind uwtable
declare dso_local void @XsMatrix_assign(ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @XsMatrix_destruct(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @XsMatrix_setValue(ptr noundef, i64 noundef, i64 noundef, double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @XsMatrix_fromQuaternion(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @XsQuaternion_empty(ptr noundef %1) #2
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %5, label %4

4:                                                ; preds = %2
  tail call void @XsMatrix_destruct(ptr noundef %0)
  br label %47

5:                                                ; preds = %2
  %6 = load <2 x double>, ptr %1, align 8, !tbaa !5
  %7 = fmul <2 x double> %6, %6
  %8 = getelementptr inbounds i8, ptr %1, i64 16
  %9 = load <2 x double>, ptr %8, align 8, !tbaa !5
  %10 = fmul <2 x double> %9, %9
  %11 = extractelement <2 x double> %6, i64 0
  %12 = extractelement <2 x double> %6, i64 1
  %13 = fmul double %11, %12
  %14 = extractelement <2 x double> %9, i64 1
  %15 = fmul double %11, %14
  %16 = extractelement <2 x double> %9, i64 0
  %17 = fmul double %12, %16
  %18 = fmul <2 x double> %6, %9
  %19 = fmul double %16, %14
  tail call void @XsMatrix_assign(ptr noundef %0, i64 noundef 3, i64 noundef 3, i64 noundef 3, ptr noundef null, i64 noundef 0)
  %20 = extractelement <2 x double> %7, i64 0
  %21 = extractelement <2 x double> %7, i64 1
  %22 = fadd double %20, %21
  %23 = extractelement <2 x double> %10, i64 0
  %24 = fsub double %22, %23
  %25 = extractelement <2 x double> %10, i64 1
  %26 = fsub double %24, %25
  tail call void @XsMatrix_setValue(ptr noundef %0, i64 noundef 0, i64 noundef 0, double noundef %26)
  %27 = fsub double %17, %15
  %28 = load double, ptr @XsMath_two, align 8, !tbaa !8
  %29 = fmul double %27, %28
  tail call void @XsMatrix_setValue(ptr noundef %0, i64 noundef 0, i64 noundef 1, double noundef %29)
  %30 = extractelement <2 x double> %18, i64 0
  %31 = extractelement <2 x double> %18, i64 1
  %32 = fadd double %30, %31
  %33 = fmul double %32, %28
  tail call void @XsMatrix_setValue(ptr noundef %0, i64 noundef 0, i64 noundef 2, double noundef %33)
  %34 = fadd double %17, %15
  %35 = fmul double %34, %28
  tail call void @XsMatrix_setValue(ptr noundef %0, i64 noundef 1, i64 noundef 0, double noundef %35)
  %36 = fsub double %20, %21
  %37 = fsub double %23, %25
  %38 = fadd double %36, %37
  tail call void @XsMatrix_setValue(ptr noundef %0, i64 noundef 1, i64 noundef 1, double noundef %38)
  %39 = fsub double %19, %13
  %40 = fmul double %39, %28
  tail call void @XsMatrix_setValue(ptr noundef %0, i64 noundef 1, i64 noundef 2, double noundef %40)
  %41 = fsub double %31, %30
  %42 = fmul double %41, %28
  tail call void @XsMatrix_setValue(ptr noundef %0, i64 noundef 2, i64 noundef 0, double noundef %42)
  %43 = fadd double %13, %19
  %44 = fmul double %43, %28
  tail call void @XsMatrix_setValue(ptr noundef %0, i64 noundef 2, i64 noundef 1, double noundef %44)
  %45 = fsub double %36, %23
  %46 = fadd double %45, %25
  tail call void @XsMatrix_setValue(ptr noundef %0, i64 noundef 2, i64 noundef 2, double noundef %46)
  br label %47

47:                                               ; preds = %5, %4
  ret void
}

declare i32 @XsQuaternion_empty(ptr noundef) local_unnamed_addr #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 = { "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 #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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"double", !6, i64 0}


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