; LLVM IR from xboot/libcg :: src (cg)

; 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.cg_matrix_t = type { double, double, double, double, double, double }

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nounwind uwtable
define dso_local void @cg_matrix_invert(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca double, align 8
  %4 = alloca double, 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 i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  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
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.cg_matrix_t, ptr %11, i32 0, i32 2
  %13 = load double, ptr %12, align 8, !tbaa !9
  %14 = fcmp oeq double %13, 0.000000e+00
  br i1 %14, label %15, label %83

15:                                               ; preds = %1
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.cg_matrix_t, ptr %16, i32 0, i32 1
  %18 = load double, ptr %17, align 8, !tbaa !12
  %19 = fcmp oeq double %18, 0.000000e+00
  br i1 %19, label %20, label %83

20:                                               ; preds = %15
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.cg_matrix_t, ptr %21, i32 0, i32 4
  %23 = load double, ptr %22, align 8, !tbaa !13
  %24 = fneg double %23
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.cg_matrix_t, ptr %25, i32 0, i32 4
  store double %24, ptr %26, align 8, !tbaa !13
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.cg_matrix_t, ptr %27, i32 0, i32 5
  %29 = load double, ptr %28, align 8, !tbaa !14
  %30 = fneg double %29
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.cg_matrix_t, ptr %31, i32 0, i32 5
  store double %30, ptr %32, align 8, !tbaa !14
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.cg_matrix_t, ptr %33, i32 0, i32 0
  %35 = load double, ptr %34, align 8, !tbaa !15
  %36 = fcmp une double %35, 1.000000e+00
  br i1 %36, label %37, label %57

37:                                               ; preds = %20
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.cg_matrix_t, ptr %38, i32 0, i32 0
  %40 = load double, ptr %39, align 8, !tbaa !15
  %41 = fcmp oeq double %40, 0.000000e+00
  br i1 %41, label %42, label %43

42:                                               ; preds = %37
  store i32 1, ptr %10, align 4
  br label %166

43:                                               ; preds = %37
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.cg_matrix_t, ptr %44, i32 0, i32 0
  %46 = load double, ptr %45, align 8, !tbaa !15
  %47 = fdiv double 1.000000e+00, %46
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.cg_matrix_t, ptr %48, i32 0, i32 0
  store double %47, ptr %49, align 8, !tbaa !15
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.cg_matrix_t, ptr %50, i32 0, i32 0
  %52 = load double, ptr %51, align 8, !tbaa !15
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.cg_matrix_t, ptr %53, i32 0, i32 4
  %55 = load double, ptr %54, align 8, !tbaa !13
  %56 = fmul double %55, %52
  store double %56, ptr %54, align 8, !tbaa !13
  br label %57

57:                                               ; preds = %43, %20
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.cg_matrix_t, ptr %58, i32 0, i32 3
  %60 = load double, ptr %59, align 8, !tbaa !16
  %61 = fcmp une double %60, 1.000000e+00
  br i1 %61, label %62, label %82

62:                                               ; preds = %57
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.cg_matrix_t, ptr %63, i32 0, i32 3
  %65 = load double, ptr %64, align 8, !tbaa !16
  %66 = fcmp oeq double %65, 0.000000e+00
  br i1 %66, label %67, label %68

67:                                               ; preds = %62
  store i32 1, ptr %10, align 4
  br label %166

68:                                               ; preds = %62
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.cg_matrix_t, ptr %69, i32 0, i32 3
  %71 = load double, ptr %70, align 8, !tbaa !16
  %72 = fdiv double 1.000000e+00, %71
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.cg_matrix_t, ptr %73, i32 0, i32 3
  store double %72, ptr %74, align 8, !tbaa !16
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.cg_matrix_t, ptr %75, i32 0, i32 3
  %77 = load double, ptr %76, align 8, !tbaa !16
  %78 = load ptr, ptr %2, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.cg_matrix_t, ptr %78, i32 0, i32 5
  %80 = load double, ptr %79, align 8, !tbaa !14
  %81 = fmul double %80, %77
  store double %81, ptr %79, align 8, !tbaa !14
  br label %82

82:                                               ; preds = %68, %57
  br label %165

83:                                               ; preds = %15, %1
  %84 = load ptr, ptr %2, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.cg_matrix_t, ptr %84, i32 0, i32 0
  %86 = load double, ptr %85, align 8, !tbaa !15
  %87 = load ptr, ptr %2, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.cg_matrix_t, ptr %87, i32 0, i32 3
  %89 = load double, ptr %88, align 8, !tbaa !16
  %90 = load ptr, ptr %2, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.cg_matrix_t, ptr %90, i32 0, i32 1
  %92 = load double, ptr %91, align 8, !tbaa !12
  %93 = load ptr, ptr %2, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.cg_matrix_t, ptr %93, i32 0, i32 2
  %95 = load double, ptr %94, align 8, !tbaa !9
  %96 = fmul double %92, %95
  %97 = fneg double %96
  %98 = call double @llvm.fmuladd.f64(double %86, double %89, double %97)
  store double %98, ptr %9, align 8, !tbaa !17
  %99 = load double, ptr %9, align 8, !tbaa !17
  %100 = fcmp une double %99, 0.000000e+00
  br i1 %100, label %101, label %164

101:                                              ; preds = %83
  %102 = load ptr, ptr %2, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.cg_matrix_t, ptr %102, i32 0, i32 0
  %104 = load double, ptr %103, align 8, !tbaa !15
  store double %104, ptr %3, align 8, !tbaa !17
  %105 = load ptr, ptr %2, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.cg_matrix_t, ptr %105, i32 0, i32 1
  %107 = load double, ptr %106, align 8, !tbaa !12
  store double %107, ptr %4, align 8, !tbaa !17
  %108 = load ptr, ptr %2, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.cg_matrix_t, ptr %108, i32 0, i32 2
  %110 = load double, ptr %109, align 8, !tbaa !9
  store double %110, ptr %5, align 8, !tbaa !17
  %111 = load ptr, ptr %2, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.cg_matrix_t, ptr %111, i32 0, i32 3
  %113 = load double, ptr %112, align 8, !tbaa !16
  store double %113, ptr %6, align 8, !tbaa !17
  %114 = load ptr, ptr %2, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.cg_matrix_t, ptr %114, i32 0, i32 4
  %116 = load double, ptr %115, align 8, !tbaa !13
  store double %116, ptr %7, align 8, !tbaa !17
  %117 = load ptr, ptr %2, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.cg_matrix_t, ptr %117, i32 0, i32 5
  %119 = load double, ptr %118, align 8, !tbaa !14
  store double %119, ptr %8, align 8, !tbaa !17
  %120 = load double, ptr %6, align 8, !tbaa !17
  %121 = load double, ptr %9, align 8, !tbaa !17
  %122 = fdiv double %120, %121
  %123 = load ptr, ptr %2, align 8, !tbaa !5
  %124 = getelementptr inbounds %struct.cg_matrix_t, ptr %123, i32 0, i32 0
  store double %122, ptr %124, align 8, !tbaa !15
  %125 = load double, ptr %4, align 8, !tbaa !17
  %126 = fneg double %125
  %127 = load double, ptr %9, align 8, !tbaa !17
  %128 = fdiv double %126, %127
  %129 = load ptr, ptr %2, align 8, !tbaa !5
  %130 = getelementptr inbounds %struct.cg_matrix_t, ptr %129, i32 0, i32 1
  store double %128, ptr %130, align 8, !tbaa !12
  %131 = load double, ptr %5, align 8, !tbaa !17
  %132 = fneg double %131
  %133 = load double, ptr %9, align 8, !tbaa !17
  %134 = fdiv double %132, %133
  %135 = load ptr, ptr %2, align 8, !tbaa !5
  %136 = getelementptr inbounds %struct.cg_matrix_t, ptr %135, i32 0, i32 2
  store double %134, ptr %136, align 8, !tbaa !9
  %137 = load double, ptr %3, align 8, !tbaa !17
  %138 = load double, ptr %9, align 8, !tbaa !17
  %139 = fdiv double %137, %138
  %140 = load ptr, ptr %2, align 8, !tbaa !5
  %141 = getelementptr inbounds %struct.cg_matrix_t, ptr %140, i32 0, i32 3
  store double %139, ptr %141, align 8, !tbaa !16
  %142 = load double, ptr %5, align 8, !tbaa !17
  %143 = load double, ptr %8, align 8, !tbaa !17
  %144 = load double, ptr %6, align 8, !tbaa !17
  %145 = load double, ptr %7, align 8, !tbaa !17
  %146 = fmul double %144, %145
  %147 = fneg double %146
  %148 = call double @llvm.fmuladd.f64(double %142, double %143, double %147)
  %149 = load double, ptr %9, align 8, !tbaa !17
  %150 = fdiv double %148, %149
  %151 = load ptr, ptr %2, align 8, !tbaa !5
  %152 = getelementptr inbounds %struct.cg_matrix_t, ptr %151, i32 0, i32 4
  store double %150, ptr %152, align 8, !tbaa !13
  %153 = load double, ptr %4, align 8, !tbaa !17
  %154 = load double, ptr %7, align 8, !tbaa !17
  %155 = load double, ptr %3, align 8, !tbaa !17
  %156 = load double, ptr %8, align 8, !tbaa !17
  %157 = fmul double %155, %156
  %158 = fneg double %157
  %159 = call double @llvm.fmuladd.f64(double %153, double %154, double %158)
  %160 = load double, ptr %9, align 8, !tbaa !17
  %161 = fdiv double %159, %160
  %162 = load ptr, ptr %2, align 8, !tbaa !5
  %163 = getelementptr inbounds %struct.cg_matrix_t, ptr %162, i32 0, i32 5
  store double %161, ptr %163, align 8, !tbaa !14
  br label %164

164:                                              ; preds = %101, %83
  br label %165

165:                                              ; preds = %164, %82
  store i32 0, ptr %10, align 4
  br label %166

166:                                              ; preds = %165, %67, %42
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %167 = load i32, ptr %10, align 4
  switch i32 %167, label %169 [
    i32 0, label %168
    i32 1, label %168
  ]

168:                                              ; preds = %166, %166
  ret void

169:                                              ; preds = %166
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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, !11, i64 16}
!10 = !{!"cg_matrix_t", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40}
!11 = !{!"double", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!10, !11, i64 32}
!14 = !{!10, !11, i64 40}
!15 = !{!10, !11, i64 0}
!16 = !{!10, !11, i64 24}
!17 = !{!11, !11, 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"

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @cg_matrix_invert(ptr nocapture noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load <2 x double>, ptr %3, align 8, !tbaa !5
  %5 = extractelement <2 x double> %4, i64 1
  %6 = fcmp oeq double %5, 0.000000e+00
  %7 = extractelement <2 x double> %4, i64 0
  %8 = fcmp oeq double %7, 0.000000e+00
  %or.cond55 = select i1 %6, i1 %8, i1 false
  br i1 %or.cond55, label %9, label %._crit_edge

9:                                                ; preds = %1
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  %12 = load <2 x double>, ptr %10, align 8, !tbaa !5
  %13 = fneg <2 x double> %12
  store <2 x double> %13, ptr %10, align 8, !tbaa !5
  %14 = load double, ptr %0, align 8, !tbaa !9
  %15 = fcmp une double %14, 1.000000e+00
  br i1 %15, label %16, label %22

16:                                               ; preds = %9
  %17 = fcmp oeq double %14, 0.000000e+00
  br i1 %17, label %57, label %18

18:                                               ; preds = %16
  %19 = fdiv double 1.000000e+00, %14
  store double %19, ptr %0, align 8, !tbaa !9
  %20 = extractelement <2 x double> %13, i64 0
  %21 = fmul double %19, %20
  store double %21, ptr %10, align 8, !tbaa !11
  br label %22

22:                                               ; preds = %18, %9
  %23 = getelementptr inbounds i8, ptr %0, i64 24
  %24 = load double, ptr %23, align 8, !tbaa !12
  %25 = fcmp oeq double %24, 1.000000e+00
  %26 = fcmp oeq double %24, 0.000000e+00
  %or.cond = or i1 %25, %26
  br i1 %or.cond, label %57, label %27

27:                                               ; preds = %22
  %28 = fdiv double 1.000000e+00, %24
  store double %28, ptr %23, align 8, !tbaa !12
  %29 = extractelement <2 x double> %13, i64 1
  %30 = fmul double %28, %29
  store double %30, ptr %11, align 8, !tbaa !13
  br label %57

._crit_edge:                                      ; preds = %1
  %31 = load double, ptr %0, align 8, !tbaa !9
  %32 = getelementptr inbounds i8, ptr %0, i64 24
  %33 = load double, ptr %32, align 8, !tbaa !12
  %34 = fneg double %7
  %35 = fmul double %5, %34
  %36 = tail call double @llvm.fmuladd.f64(double %31, double %33, double %35)
  %37 = fcmp une double %36, 0.000000e+00
  br i1 %37, label %38, label %57

38:                                               ; preds = %._crit_edge
  %39 = getelementptr inbounds i8, ptr %0, i64 32
  %40 = insertelement <2 x double> poison, double %33, i64 0
  %41 = insertelement <2 x double> %40, double %34, i64 1
  %42 = insertelement <2 x double> poison, double %36, i64 0
  %43 = shufflevector <2 x double> %42, <2 x double> poison, <2 x i32> zeroinitializer
  %44 = fdiv <2 x double> %41, %43
  store <2 x double> %44, ptr %0, align 8, !tbaa !5
  %45 = fneg double %5
  %46 = insertelement <2 x double> poison, double %45, i64 0
  %47 = insertelement <2 x double> %46, double %31, i64 1
  %48 = fdiv <2 x double> %47, %43
  store <2 x double> %48, ptr %2, align 8, !tbaa !5
  %49 = insertelement <2 x double> %40, double %31, i64 1
  %50 = fneg <2 x double> %49
  %51 = load <2 x double>, ptr %39, align 8, !tbaa !5
  %52 = fmul <2 x double> %51, %50
  %53 = shufflevector <2 x double> %52, <2 x double> poison, <2 x i32> <i32 1, i32 0>
  %54 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %4, <2 x double> %51, <2 x double> %53)
  %55 = fdiv <2 x double> %54, %43
  %56 = shufflevector <2 x double> %55, <2 x double> poison, <2 x i32> <i32 1, i32 0>
  store <2 x double> %56, ptr %39, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %27, %22, %38, %._crit_edge, %16
  ret void
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #2 = { 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, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"cg_matrix_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!11 = !{!10, !6, i64 32}
!12 = !{!10, !6, i64 24}
!13 = !{!10, !6, i64 40}


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