; LLVM IR from moarseniy/CudaFEMproject :: deprecated/Linal2/src/Linal2.ll (ZN6Matrix9det_gaussEv)

; 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.Matrix = type { i32, i32, i8, i8, ptr }

; 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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6MatrixaSERKS_(ptr dead_on_unwind noalias writable sret(%class.Matrix) align 8, ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZN6Matrix5GaussEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN6Matrix9det_gaussEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca float, align 4
  %4 = alloca %class.Matrix, align 8
  %5 = alloca %class.Matrix, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %11 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store float 1.000000e+00, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %4) #3
  %12 = getelementptr inbounds %class.Matrix, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds %class.Matrix, ptr %11, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !15
  call void @_ZN6MatrixC1Eii(ptr noundef nonnull align 8 dereferenceable(24) %4, i32 noundef %13, i32 noundef %15)
  invoke void @_ZN6MatrixaSERKS_(ptr dead_on_unwind writable sret(%class.Matrix) align 8 %5, ptr noundef nonnull align 8 dereferenceable(24) %4, ptr noundef nonnull align 8 dereferenceable(24) %11)
          to label %16 unwind label %22

16:                                               ; preds = %1
  call void @_ZN6MatrixD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %5) #3
  %17 = getelementptr inbounds %class.Matrix, ptr %4, i32 0, i32 2
  %18 = load i8, ptr %17, align 8, !tbaa !16, !range !17, !noundef !18
  %19 = trunc i8 %18 to i1
  br i1 %19, label %26, label %20

20:                                               ; preds = %16
  %21 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN6Matrix5GaussEv(ptr noundef nonnull align 8 dereferenceable(24) %4)
  br label %26

22:                                               ; preds = %1
  %23 = landingpad { ptr, i32 }
          cleanup
  %24 = extractvalue { ptr, i32 } %23, 0
  store ptr %24, ptr %6, align 8
  %25 = extractvalue { ptr, i32 } %23, 1
  store i32 %25, ptr %7, align 4
  call void @_ZN6MatrixD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %4) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %68

26:                                               ; preds = %20, %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !19
  br label %27

27:                                               ; preds = %63, %26
  %28 = load i32, ptr %8, align 4, !tbaa !19
  %29 = getelementptr inbounds %class.Matrix, ptr %11, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !11
  %31 = icmp slt i32 %28, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %27
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %66

33:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !19
  br label %34

34:                                               ; preds = %59, %33
  %35 = load i32, ptr %10, align 4, !tbaa !19
  %36 = getelementptr inbounds %class.Matrix, ptr %11, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !15
  %38 = icmp slt i32 %35, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %34
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %62

40:                                               ; preds = %34
  %41 = load i32, ptr %8, align 4, !tbaa !19
  %42 = load i32, ptr %10, align 4, !tbaa !19
  %43 = icmp eq i32 %41, %42
  br i1 %43, label %44, label %58

44:                                               ; preds = %40
  %45 = getelementptr inbounds %class.Matrix, ptr %4, i32 0, i32 4
  %46 = load ptr, ptr %45, align 8, !tbaa !20
  %47 = load i32, ptr %10, align 4, !tbaa !19
  %48 = load i32, ptr %8, align 4, !tbaa !19
  %49 = getelementptr inbounds %class.Matrix, ptr %11, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !15
  %51 = mul nsw i32 %48, %50
  %52 = add nsw i32 %47, %51
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds float, ptr %46, i64 %53
  %55 = load float, ptr %54, align 4, !tbaa !9
  %56 = load float, ptr %3, align 4, !tbaa !9
  %57 = fmul float %56, %55
  store float %57, ptr %3, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %44, %40
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %10, align 4, !tbaa !19
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %10, align 4, !tbaa !19
  br label %34, !llvm.loop !21

62:                                               ; preds = %39
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %8, align 4, !tbaa !19
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %8, align 4, !tbaa !19
  br label %27, !llvm.loop !23

66:                                               ; preds = %32
  %67 = load float, ptr %3, align 4, !tbaa !9
  store i32 1, ptr %9, align 4
  call void @_ZN6MatrixD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %4) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret float %67

68:                                               ; preds = %22
  %69 = load ptr, ptr %6, align 8
  %70 = load i32, ptr %7, align 4
  %71 = insertvalue { ptr, i32 } poison, ptr %69, 0
  %72 = insertvalue { ptr, i32 } %71, i32 %70, 1
  resume { ptr, i32 } %72
}

declare void @_ZN6MatrixC1Eii(ptr, i32, i32)

declare void @_ZN6MatrixD1Ev(ptr)

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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 #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 = !{!"float", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS6Matrix", !13, i64 0, !13, i64 4, !14, i64 8, !14, i64 9, !6, i64 16}
!13 = !{!"int", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!12, !13, i64 4}
!16 = !{!12, !14, i64 8}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!13, !13, i64 0}
!20 = !{!12, !6, i64 16}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


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

%class.Matrix = type { i32, i32, i8, i8, ptr }

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

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6MatrixaSERKS_(ptr dead_on_unwind noalias writable sret(%class.Matrix) align 8, ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZN6Matrix5GaussEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN6Matrix9det_gaussEv(ptr noundef nonnull align 8 dereferenceable(24) %0) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca %class.Matrix, align 8
  %3 = alloca %class.Matrix, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #3
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !12
  call void @_ZN6MatrixC1Eii(ptr noundef nonnull align 8 dereferenceable(24) %2, i32 noundef %4, i32 noundef %6)
  invoke void @_ZN6MatrixaSERKS_(ptr dead_on_unwind nonnull writable sret(%class.Matrix) align 8 %3, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 8 dereferenceable(24) %0)
          to label %7 unwind label %13

7:                                                ; preds = %1
  call void @_ZN6MatrixD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %3) #3
  %8 = getelementptr inbounds i8, ptr %2, i64 8
  %9 = load i8, ptr %8, align 8, !tbaa !13, !range !14, !noundef !15
  %10 = trunc nuw i8 %9 to i1
  br i1 %10, label %15, label %11

11:                                               ; preds = %7
  %12 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN6Matrix5GaussEv(ptr noundef nonnull align 8 dereferenceable(24) %2)
  br label %15

13:                                               ; preds = %1
  %14 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN6MatrixD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %2) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #3
  resume { ptr, i32 } %14

15:                                               ; preds = %11, %7
  %16 = load i32, ptr %0, align 8, !tbaa !5
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %.preheader.lr.ph, label %._crit_edge19

.preheader.lr.ph:                                 ; preds = %15
  %18 = load i32, ptr %5, align 4, !tbaa !12
  %19 = icmp sgt i32 %18, 0
  %20 = getelementptr inbounds i8, ptr %2, i64 16
  %21 = load ptr, ptr %20, align 8
  br i1 %19, label %.preheader.us.preheader, label %._crit_edge19

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %22 = zext nneg i32 %18 to i64
  %wide.trip.count26 = zext nneg i32 %16 to i64
  %indvars.iv2328 = add nuw nsw i64 %22, 1
  %xtraiter = and i64 %22, 3
  %23 = icmp ult i32 %18, 4
  %unroll_iter = and i64 %22, 2147483644
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv23 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next24, %._crit_edge.us ]
  %.01317.us = phi float [ 1.000000e+00, %.preheader.us.preheader ], [ %.2.us.lcssa, %._crit_edge.us ]
  %24 = mul nuw i64 %indvars.iv23, %indvars.iv2328
  %25 = getelementptr inbounds float, ptr %21, i64 %24
  br i1 %23, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %45
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %45 ], [ 0, %.preheader.us ]
  %.115.us = phi float [ %.2.us.3, %45 ], [ %.01317.us, %.preheader.us ]
  %niter = phi i64 [ %niter.next.3, %45 ], [ 0, %.preheader.us ]
  %26 = icmp eq i64 %indvars.iv23, %indvars.iv
  br i1 %26, label %27, label %30

27:                                               ; preds = %.preheader.us.new
  %28 = load float, ptr %25, align 4, !tbaa !16
  %29 = fmul float %.115.us, %28
  br label %30

30:                                               ; preds = %27, %.preheader.us.new
  %.2.us = phi float [ %29, %27 ], [ %.115.us, %.preheader.us.new ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %31 = icmp eq i64 %indvars.iv23, %indvars.iv.next
  br i1 %31, label %32, label %35

32:                                               ; preds = %30
  %33 = load float, ptr %25, align 4, !tbaa !16
  %34 = fmul float %.2.us, %33
  br label %35

35:                                               ; preds = %32, %30
  %.2.us.1 = phi float [ %34, %32 ], [ %.2.us, %30 ]
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %36 = icmp eq i64 %indvars.iv23, %indvars.iv.next.1
  br i1 %36, label %37, label %40

37:                                               ; preds = %35
  %38 = load float, ptr %25, align 4, !tbaa !16
  %39 = fmul float %.2.us.1, %38
  br label %40

40:                                               ; preds = %37, %35
  %.2.us.2 = phi float [ %39, %37 ], [ %.2.us.1, %35 ]
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %41 = icmp eq i64 %indvars.iv23, %indvars.iv.next.2
  br i1 %41, label %42, label %45

42:                                               ; preds = %40
  %43 = load float, ptr %25, align 4, !tbaa !16
  %44 = fmul float %.2.us.2, %43
  br label %45

45:                                               ; preds = %42, %40
  %.2.us.3 = phi float [ %44, %42 ], [ %.2.us.2, %40 ]
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !18

._crit_edge.us.unr-lcssa:                         ; preds = %45, %.preheader.us
  %.2.us.lcssa.ph = phi float [ poison, %.preheader.us ], [ %.2.us.3, %45 ]
  %indvars.iv.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next.3, %45 ]
  %.115.us.unr = phi float [ %.01317.us, %.preheader.us ], [ %.2.us.3, %45 ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa, %50
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %50 ], [ %indvars.iv.unr, %._crit_edge.us.unr-lcssa ]
  %.115.us.epil = phi float [ %.2.us.epil, %50 ], [ %.115.us.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %50 ], [ 0, %._crit_edge.us.unr-lcssa ]
  %46 = icmp eq i64 %indvars.iv23, %indvars.iv.epil
  br i1 %46, label %47, label %50

47:                                               ; preds = %.epil.preheader
  %48 = load float, ptr %25, align 4, !tbaa !16
  %49 = fmul float %.115.us.epil, %48
  br label %50

50:                                               ; preds = %47, %.epil.preheader
  %.2.us.epil = phi float [ %49, %47 ], [ %.115.us.epil, %.epil.preheader ]
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.us, label %.epil.preheader, !llvm.loop !20

._crit_edge.us:                                   ; preds = %50, %._crit_edge.us.unr-lcssa
  %.2.us.lcssa = phi float [ %.2.us.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %.2.us.epil, %50 ]
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %exitcond27.not = icmp eq i64 %indvars.iv.next24, %wide.trip.count26
  br i1 %exitcond27.not, label %._crit_edge19, label %.preheader.us, !llvm.loop !22

._crit_edge19:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %15
  %.013.lcssa = phi float [ 1.000000e+00, %15 ], [ 1.000000e+00, %.preheader.lr.ph ], [ %.2.us.lcssa, %._crit_edge.us ]
  call void @_ZN6MatrixD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %2) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #3
  ret float %.013.lcssa
}

declare void @_ZN6MatrixC1Eii(ptr, i32, i32) local_unnamed_addr

declare void @_ZN6MatrixD1Ev(ptr) local_unnamed_addr

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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 #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, !7, i64 0}
!6 = !{!"_ZTS6Matrix", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 9, !11, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 4}
!13 = !{!6, !10, i64 8}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!17, !17, i64 0}
!17 = !{!"float", !8, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.unroll.disable"}
!22 = distinct !{!22, !19}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass