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

; 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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZN6Matrix5GaussEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca float, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store float 0.000000e+00, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !11
  br label %9

9:                                                ; preds = %88, %1
  %10 = load i32, ptr %4, align 4, !tbaa !11
  %11 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !13
  %13 = icmp slt i32 %10, %12
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %16 = load i32, ptr %4, align 4, !tbaa !11
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %6, align 4, !tbaa !11
  br label %18

18:                                               ; preds = %84, %15
  %19 = load i32, ptr %6, align 4, !tbaa !11
  %20 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = icmp slt i32 %19, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %87

24:                                               ; preds = %18
  %25 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 4
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = load i32, ptr %4, align 4, !tbaa !11
  %28 = load i32, ptr %6, align 4, !tbaa !11
  %29 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !17
  %31 = mul nsw i32 %28, %30
  %32 = add nsw i32 %27, %31
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds float, ptr %26, i64 %33
  %35 = load float, ptr %34, align 4, !tbaa !9
  %36 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 4
  %37 = load ptr, ptr %36, align 8, !tbaa !16
  %38 = load i32, ptr %4, align 4, !tbaa !11
  %39 = load i32, ptr %4, align 4, !tbaa !11
  %40 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !17
  %42 = mul nsw i32 %39, %41
  %43 = add nsw i32 %38, %42
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds float, ptr %37, i64 %44
  %46 = load float, ptr %45, align 4, !tbaa !9
  %47 = fdiv float %35, %46
  store float %47, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %48

48:                                               ; preds = %80, %24
  %49 = load i32, ptr %7, align 4, !tbaa !11
  %50 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !17
  %52 = icmp slt i32 %49, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %48
  store i32 8, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %83

54:                                               ; preds = %48
  %55 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 4
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  %57 = load i32, ptr %7, align 4, !tbaa !11
  %58 = load i32, ptr %4, align 4, !tbaa !11
  %59 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 1
  %60 = load i32, ptr %59, align 4, !tbaa !17
  %61 = mul nsw i32 %58, %60
  %62 = add nsw i32 %57, %61
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds float, ptr %56, i64 %63
  %65 = load float, ptr %64, align 4, !tbaa !9
  %66 = load float, ptr %3, align 4, !tbaa !9
  %67 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 4
  %68 = load ptr, ptr %67, align 8, !tbaa !16
  %69 = load i32, ptr %7, align 4, !tbaa !11
  %70 = load i32, ptr %6, align 4, !tbaa !11
  %71 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 1
  %72 = load i32, ptr %71, align 4, !tbaa !17
  %73 = mul nsw i32 %70, %72
  %74 = add nsw i32 %69, %73
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds float, ptr %68, i64 %75
  %77 = load float, ptr %76, align 4, !tbaa !9
  %78 = fneg float %65
  %79 = call float @llvm.fmuladd.f32(float %78, float %66, float %77)
  store float %79, ptr %76, align 4, !tbaa !9
  br label %80

80:                                               ; preds = %54
  %81 = load i32, ptr %7, align 4, !tbaa !11
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %7, align 4, !tbaa !11
  br label %48, !llvm.loop !18

83:                                               ; preds = %53
  br label %84

84:                                               ; preds = %83
  %85 = load i32, ptr %6, align 4, !tbaa !11
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %6, align 4, !tbaa !11
  br label %18, !llvm.loop !20

87:                                               ; preds = %23
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %4, align 4, !tbaa !11
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %4, align 4, !tbaa !11
  br label %9, !llvm.loop !21

91:                                               ; preds = %14
  %92 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 2
  store i8 1, ptr %92, align 8, !tbaa !22
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret ptr %8
}

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZN6Matrix5GaussEv(ptr noundef nonnull returned align 8 dereferenceable(24) %0) local_unnamed_addr #1 align 2 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load ptr, ptr %4, align 8
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 4
  %.fr24 = freeze i32 %7
  %8 = add i32 %.fr24, 1
  %9 = icmp sgt i32 %.fr24, 0
  br i1 %9, label %.lr.ph.split.us.preheader, label %._crit_edge

.lr.ph.split.us.preheader:                        ; preds = %.lr.ph
  %10 = zext nneg i32 %.fr24 to i64
  %11 = zext nneg i32 %2 to i64
  %wide.trip.count37 = zext nneg i32 %2 to i64
  %12 = shl nuw nsw i64 %10, 2
  %13 = shl nuw nsw i64 %10, 2
  %14 = mul nuw nsw i64 %10, %11
  %15 = shl nuw i64 %14, 2
  %scevgep43 = getelementptr i8, ptr %5, i64 %15
  %scevgep45 = getelementptr i8, ptr %5, i64 %12
  %16 = getelementptr i8, ptr %5, i64 %12
  %min.iters.check = icmp ult i32 %.fr24, 8
  %n.vec = and i64 %10, 2147483640
  %cmp.n = icmp eq i64 %n.vec, %10
  %xtraiter = and i64 %10, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  %17 = add nsw i64 %10, -1
  br label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph.split.us.preheader, %.loopexit.us
  %indvars.iv34 = phi i64 [ 0, %.lr.ph.split.us.preheader ], [ %indvars.iv.next35, %.loopexit.us ]
  %indvars.iv27 = phi i64 [ 1, %.lr.ph.split.us.preheader ], [ %indvars.iv.next28, %.loopexit.us ]
  %18 = mul i64 %13, %indvars.iv34
  %scevgep = getelementptr i8, ptr %16, i64 %18
  %19 = trunc i64 %indvars.iv34 to i32
  %20 = mul i32 %.fr24, %19
  %21 = zext i32 %20 to i64
  %22 = shl nuw nsw i64 %21, 2
  %scevgep44 = getelementptr i8, ptr %5, i64 %22
  %scevgep46 = getelementptr i8, ptr %scevgep45, i64 %22
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %23 = icmp ult i64 %indvars.iv.next35, %11
  br i1 %23, label %.lr.ph22.us, label %.loopexit.us

.loopexit.us:                                     ; preds = %._crit_edge.us.us, %.lr.ph.split.us
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %exitcond38.not = icmp eq i64 %indvars.iv.next35, %wide.trip.count37
  br i1 %exitcond38.not, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !12

.lr.ph22.us:                                      ; preds = %.lr.ph.split.us
  %24 = trunc nuw nsw i64 %indvars.iv34 to i32
  %25 = mul i32 %8, %24
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds float, ptr %5, i64 %26
  %28 = trunc i64 %indvars.iv34 to i32
  %29 = mul i32 %.fr24, %28
  %30 = zext i32 %29 to i64
  %invariant.gep41 = getelementptr inbounds float, ptr %5, i64 %indvars.iv34
  %invariant.gep = getelementptr inbounds float, ptr %5, i64 %30
  %bound0 = icmp ult ptr %scevgep, %scevgep46
  %bound1 = icmp ult ptr %scevgep44, %scevgep43
  %found.conflict = and i1 %bound0, %bound1
  br label %.lr.ph.us.us

.lr.ph.us.us:                                     ; preds = %._crit_edge.us.us, %.lr.ph22.us
  %indvars.iv29 = phi i64 [ %indvars.iv.next30, %._crit_edge.us.us ], [ %indvars.iv27, %.lr.ph22.us ]
  %31 = mul nuw nsw i64 %indvars.iv29, %10
  %gep42 = getelementptr inbounds float, ptr %invariant.gep41, i64 %31
  %32 = load float, ptr %gep42, align 4, !tbaa !14
  %33 = load float, ptr %27, align 4, !tbaa !14
  %34 = fdiv float %32, %33
  %invariant.gep39 = getelementptr inbounds float, ptr %5, i64 %31
  %brmerge = select i1 %min.iters.check, i1 true, i1 %found.conflict
  br i1 %brmerge, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.us.us
  %broadcast.splatinsert = insertelement <4 x float> poison, float %34, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %35 = getelementptr inbounds float, ptr %invariant.gep, i64 %index
  %36 = getelementptr inbounds i8, ptr %35, i64 16
  %wide.load = load <4 x float>, ptr %35, align 4, !tbaa !14, !alias.scope !16
  %wide.load47 = load <4 x float>, ptr %36, align 4, !tbaa !14, !alias.scope !16
  %37 = getelementptr inbounds float, ptr %invariant.gep39, i64 %index
  %38 = getelementptr inbounds i8, ptr %37, i64 16
  %wide.load48 = load <4 x float>, ptr %37, align 4, !tbaa !14, !alias.scope !19, !noalias !16
  %wide.load49 = load <4 x float>, ptr %38, align 4, !tbaa !14, !alias.scope !19, !noalias !16
  %39 = fneg <4 x float> %wide.load
  %40 = fneg <4 x float> %wide.load47
  %41 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %39, <4 x float> %broadcast.splat, <4 x float> %wide.load48)
  %42 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %40, <4 x float> %broadcast.splat, <4 x float> %wide.load49)
  store <4 x float> %41, ptr %37, align 4, !tbaa !14, !alias.scope !19, !noalias !16
  store <4 x float> %42, ptr %38, align 4, !tbaa !14, !alias.scope !19, !noalias !16
  %index.next = add nuw i64 %index, 8
  %43 = icmp eq i64 %index.next, %n.vec
  br i1 %43, label %middle.block, label %vector.body, !llvm.loop !21

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %.lr.ph.us.us, %middle.block
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.us.us ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %gep.prol = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv.ph
  %44 = load float, ptr %gep.prol, align 4, !tbaa !14
  %gep40.prol = getelementptr inbounds float, ptr %invariant.gep39, i64 %indvars.iv.ph
  %45 = load float, ptr %gep40.prol, align 4, !tbaa !14
  %46 = fneg float %44
  %47 = tail call float @llvm.fmuladd.f32(float %46, float %34, float %45)
  store float %47, ptr %gep40.prol, align 4, !tbaa !14
  %indvars.iv.next.prol = or disjoint i64 %indvars.iv.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %48 = icmp eq i64 %indvars.iv.ph, %17
  br i1 %48, label %._crit_edge.us.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %gep = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv
  %49 = load float, ptr %gep, align 4, !tbaa !14
  %gep40 = getelementptr inbounds float, ptr %invariant.gep39, i64 %indvars.iv
  %50 = load float, ptr %gep40, align 4, !tbaa !14
  %51 = fneg float %49
  %52 = tail call float @llvm.fmuladd.f32(float %51, float %34, float %50)
  store float %52, ptr %gep40, align 4, !tbaa !14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %gep.1 = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv.next
  %53 = load float, ptr %gep.1, align 4, !tbaa !14
  %gep40.1 = getelementptr inbounds float, ptr %invariant.gep39, i64 %indvars.iv.next
  %54 = load float, ptr %gep40.1, align 4, !tbaa !14
  %55 = fneg float %53
  %56 = tail call float @llvm.fmuladd.f32(float %55, float %34, float %54)
  store float %56, ptr %gep40.1, align 4, !tbaa !14
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %10
  br i1 %exitcond.not.1, label %._crit_edge.us.us, label %scalar.ph, !llvm.loop !24

._crit_edge.us.us:                                ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  %exitcond33.not = icmp eq i64 %indvars.iv.next30, %wide.trip.count37
  br i1 %exitcond33.not, label %.loopexit.us, label %.lr.ph.us.us, !llvm.loop !25

._crit_edge:                                      ; preds = %.loopexit.us, %.lr.ph, %1
  %57 = getelementptr inbounds i8, ptr %0, i64 8
  store i8 1, ptr %57, align 8, !tbaa !26
  ret ptr %0
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !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 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !8, i64 0}
!16 = !{!17}
!17 = distinct !{!17, !18}
!18 = distinct !{!18, !"LVerDomain"}
!19 = !{!20}
!20 = distinct !{!20, !18}
!21 = distinct !{!21, !13, !22, !23}
!22 = !{!"llvm.loop.isvectorized", i32 1}
!23 = !{!"llvm.loop.unroll.runtime.disable"}
!24 = distinct !{!24, !13, !22}
!25 = distinct !{!25, !13}
!26 = !{!6, !10, i64 8}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass