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

; 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: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN6MatrixclEii(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef) #1 align 2

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

17:                                               ; preds = %62, %5
  %18 = load i32, ptr %12, align 4, !tbaa !9
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  store i32 2, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  br label %65

22:                                               ; preds = %17
  %23 = load i32, ptr %12, align 4, !tbaa !9
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = icmp ne i32 %23, %24
  br i1 %25, label %26, label %61

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  store i32 0, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %55, %26
  %28 = load i32, ptr %14, align 4, !tbaa !9
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  store i32 5, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  br label %58

32:                                               ; preds = %27
  %33 = load i32, ptr %14, align 4, !tbaa !9
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = icmp ne i32 %33, %34
  br i1 %35, label %36, label %54

36:                                               ; preds = %32
  %37 = getelementptr inbounds %class.Matrix, ptr %16, i32 0, i32 4
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = load i32, ptr %14, align 4, !tbaa !9
  %40 = load i32, ptr %12, align 4, !tbaa !9
  %41 = getelementptr inbounds %class.Matrix, ptr %16, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !14
  %43 = mul nsw i32 %40, %42
  %44 = add nsw i32 %39, %43
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds float, ptr %38, i64 %45
  %47 = load float, ptr %46, align 4, !tbaa !15
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = load i32, ptr %15, align 4, !tbaa !9
  %51 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN6MatrixclEii(ptr noundef nonnull align 8 dereferenceable(24) %48, i32 noundef %49, i32 noundef %50)
  store float %47, ptr %51, align 4, !tbaa !15
  %52 = load i32, ptr %15, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %15, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %36, %32
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %14, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %14, align 4, !tbaa !9
  br label %27, !llvm.loop !17

58:                                               ; preds = %31
  %59 = load i32, ptr %11, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %11, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %58, %22
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %12, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %12, align 4, !tbaa !9
  br label %17, !llvm.loop !19

65:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  ret void
}

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


; 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 nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN6MatrixclEii(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6Matrix10Get_matrixEiRS_ii(ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) %0, i32 noundef %1, ptr noundef nonnull align 8 dereferenceable(24) %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 align 2 {
  %6 = icmp sgt i32 %1, 0
  br i1 %6, label %.lr.ph29, label %._crit_edge30

.lr.ph29:                                         ; preds = %5
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  br label %9

9:                                                ; preds = %22, %.lr.ph29
  %.01826.us = phi i32 [ 0, %.lr.ph29 ], [ %23, %22 ]
  %.01925.us = phi i32 [ 0, %.lr.ph29 ], [ %.120.us, %22 ]
  %.not.us = icmp eq i32 %.01826.us, %3
  br i1 %.not.us, label %22, label %.preheader.us

.preheader.us:                                    ; preds = %9, %20
  %.024.us = phi i32 [ %.1.us, %20 ], [ 0, %9 ]
  %.01723.us = phi i32 [ %21, %20 ], [ 0, %9 ]
  %.not22.us = icmp eq i32 %.01723.us, %4
  br i1 %.not22.us, label %20, label %10

10:                                               ; preds = %.preheader.us
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = load i32, ptr %8, align 4, !tbaa !12
  %13 = mul nsw i32 %12, %.01826.us
  %14 = add nsw i32 %13, %.01723.us
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds float, ptr %11, i64 %15
  %17 = load float, ptr %16, align 4, !tbaa !13
  %18 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN6MatrixclEii(ptr noundef nonnull align 8 dereferenceable(24) %2, i32 noundef %.01925.us, i32 noundef %.024.us)
  store float %17, ptr %18, align 4, !tbaa !13
  %19 = add nsw i32 %.024.us, 1
  br label %20

20:                                               ; preds = %10, %.preheader.us
  %.1.us = phi i32 [ %19, %10 ], [ %.024.us, %.preheader.us ]
  %21 = add nuw nsw i32 %.01723.us, 1
  %exitcond.not = icmp eq i32 %21, %1
  br i1 %exitcond.not, label %._crit_edge.us, label %.preheader.us, !llvm.loop !15

22:                                               ; preds = %._crit_edge.us, %9
  %.120.us = phi i32 [ %24, %._crit_edge.us ], [ %.01925.us, %9 ]
  %23 = add nuw nsw i32 %.01826.us, 1
  %exitcond31.not = icmp eq i32 %23, %1
  br i1 %exitcond31.not, label %._crit_edge30, label %9, !llvm.loop !17

._crit_edge.us:                                   ; preds = %20
  %24 = add nsw i32 %.01925.us, 1
  br label %22

._crit_edge30:                                    ; preds = %22, %5
  ret void
}

attributes #0 = { 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" }

!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, !11, i64 16}
!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 = !{!14, !14, i64 0}
!14 = !{!"float", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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