; LLVM IR from JoshuaSBrown/QC_Tools :: src/libcatnip/matrix.ll (ZN6catnip11Matrix_copyERKNS_6MatrixE)

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

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

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6catnip11Matrix_copyERKNS_6MatrixE(ptr dead_on_unwind noalias writable sret(%"class.catnip::Matrix") align 8 %0, ptr noundef nonnull align 8 dereferenceable(24) %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  store ptr %1, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = call noundef i32 @_ZNK6catnip6Matrix8get_rowsEv(ptr noundef nonnull align 8 dereferenceable(24) %8)
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = call noundef i32 @_ZNK6catnip6Matrix8get_colsEv(ptr noundef nonnull align 8 dereferenceable(24) %10)
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = call noundef i32 @_ZNK6catnip6Matrix8get_shelEv(ptr noundef nonnull align 8 dereferenceable(24) %12)
  call void @_ZN6catnip6MatrixC1Eiii(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %9, i32 noundef %11, i32 noundef %13)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i32 1, ptr %4, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %49, %2
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call noundef i32 @_ZNK6catnip6Matrix8get_rowsEv(ptr noundef nonnull align 8 dereferenceable(24) %16)
  %18 = icmp sle i32 %15, %17
  br i1 %18, label %19, label %52

19:                                               ; preds = %14
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %45, %19
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = call noundef i32 @_ZNK6catnip6Matrix8get_colsEv(ptr noundef nonnull align 8 dereferenceable(24) %22)
  %24 = icmp sle i32 %21, %23
  br i1 %24, label %25, label %48

25:                                               ; preds = %20
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %41, %25
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = call noundef i32 @_ZNK6catnip6Matrix8get_shelEv(ptr noundef nonnull align 8 dereferenceable(24) %28)
  %30 = icmp sle i32 %27, %29
  br i1 %30, label %31, label %44

31:                                               ; preds = %26
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = call noundef double @_ZNK6catnip6Matrix8get_elemEiii(ptr noundef nonnull align 8 dereferenceable(24) %32, i32 noundef %33, i32 noundef %34, i32 noundef %35)
  store double %36, ptr %7, align 8, !tbaa !11
  %37 = load double, ptr %7, align 8, !tbaa !11
  %38 = load i32, ptr %4, align 4, !tbaa !9
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN6catnip6Matrix8set_elemEdiii(ptr noundef nonnull align 8 dereferenceable(24) %0, double noundef %37, i32 noundef %38, i32 noundef %39, i32 noundef %40)
  br label %41

41:                                               ; preds = %31
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %6, align 4, !tbaa !9
  br label %26, !llvm.loop !13

44:                                               ; preds = %26
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %5, align 4, !tbaa !9
  br label %20, !llvm.loop !15

48:                                               ; preds = %20
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %4, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %4, align 4, !tbaa !9
  br label %14, !llvm.loop !16

52:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_ZNK6catnip6Matrix8get_elemEiii(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef, i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6catnip6Matrix8set_elemEdiii(ptr noundef nonnull align 8 dereferenceable(24), double noundef, i32 noundef, i32 noundef, i32 noundef) #2 align 2

declare void @_ZN6catnip6MatrixC1Eiii(ptr, i32, i32, i32)

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6catnip11Matrix_copyERKNS_6MatrixE(ptr dead_on_unwind noalias writable sret(%"class.catnip::Matrix") align 8 %0, ptr noundef nonnull align 8 dereferenceable(24) %1) local_unnamed_addr #1 {
  %3 = tail call noundef i32 @_ZNK6catnip6Matrix8get_rowsEv(ptr noundef nonnull align 8 dereferenceable(24) %1)
  %4 = tail call noundef i32 @_ZNK6catnip6Matrix8get_colsEv(ptr noundef nonnull align 8 dereferenceable(24) %1)
  %5 = tail call noundef i32 @_ZNK6catnip6Matrix8get_shelEv(ptr noundef nonnull align 8 dereferenceable(24) %1)
  tail call void @_ZN6catnip6MatrixC1Eiii(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %3, i32 noundef %4, i32 noundef %5)
  %6 = tail call noundef i32 @_ZNK6catnip6Matrix8get_rowsEv(ptr noundef nonnull align 8 dereferenceable(24) %1)
  %.not29 = icmp slt i32 %6, 1
  br i1 %.not29, label %._crit_edge31, label %.preheader23

.preheader23:                                     ; preds = %2, %._crit_edge28
  %.030 = phi i32 [ %14, %._crit_edge28 ], [ 1, %2 ]
  %7 = tail call noundef i32 @_ZNK6catnip6Matrix8get_colsEv(ptr noundef nonnull align 8 dereferenceable(24) %1)
  %.not2126 = icmp slt i32 %7, 1
  br i1 %.not2126, label %._crit_edge28, label %.preheader

.preheader:                                       ; preds = %.preheader23, %._crit_edge
  %.02027 = phi i32 [ %12, %._crit_edge ], [ 1, %.preheader23 ]
  %8 = tail call noundef i32 @_ZNK6catnip6Matrix8get_shelEv(ptr noundef nonnull align 8 dereferenceable(24) %1)
  %.not2224 = icmp slt i32 %8, 1
  br i1 %.not2224, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.01925 = phi i32 [ %10, %.lr.ph ], [ 1, %.preheader ]
  %9 = tail call noundef double @_ZNK6catnip6Matrix8get_elemEiii(ptr noundef nonnull align 8 dereferenceable(24) %1, i32 noundef %.030, i32 noundef %.02027, i32 noundef %.01925)
  tail call void @_ZN6catnip6Matrix8set_elemEdiii(ptr noundef nonnull align 8 dereferenceable(24) %0, double noundef %9, i32 noundef %.030, i32 noundef %.02027, i32 noundef %.01925)
  %10 = add nuw nsw i32 %.01925, 1
  %11 = tail call noundef i32 @_ZNK6catnip6Matrix8get_shelEv(ptr noundef nonnull align 8 dereferenceable(24) %1)
  %.not22.not = icmp slt i32 %.01925, %11
  br i1 %.not22.not, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %12 = add nuw nsw i32 %.02027, 1
  %13 = tail call noundef i32 @_ZNK6catnip6Matrix8get_colsEv(ptr noundef nonnull align 8 dereferenceable(24) %1)
  %.not21.not = icmp slt i32 %.02027, %13
  br i1 %.not21.not, label %.preheader, label %._crit_edge28, !llvm.loop !7

._crit_edge28:                                    ; preds = %._crit_edge, %.preheader23
  %14 = add nuw nsw i32 %.030, 1
  %15 = tail call noundef i32 @_ZNK6catnip6Matrix8get_rowsEv(ptr noundef nonnull align 8 dereferenceable(24) %1)
  %.not.not = icmp slt i32 %.030, %15
  br i1 %.not.not, label %.preheader23, label %._crit_edge31, !llvm.loop !8

._crit_edge31:                                    ; preds = %._crit_edge28, %2
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_ZNK6catnip6Matrix8get_elemEiii(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6catnip6Matrix8set_elemEdiii(ptr noundef nonnull align 8 dereferenceable(24), double noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

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

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

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}
!8 = distinct !{!8, !6}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass