; LLVM IR from SoloGameDevGitHub/AIEngine :: Miscellaneous/Matrix.ll (ZN6Matrix4copyERKS_RS_)

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

@.str.1 = external hidden unnamed_addr constant [85 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [43 x i8], align 1
@__PRETTY_FUNCTION__._ZN6Matrix4copyERKS_RS_ = external hidden unnamed_addr constant [51 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [37 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; 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 nounwind uwtable
declare dso_local noundef double @_ZNK6Matrix3getEii(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef) #2 align 2

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6Matrix4copyERKS_RS_(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call noundef i32 @_ZNK6Matrix10getColumnsEv(ptr noundef nonnull align 8 dereferenceable(32) %9)
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call noundef i32 @_ZNK6Matrix10getColumnsEv(ptr noundef nonnull align 8 dereferenceable(32) %11)
  %13 = icmp eq i32 %10, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  br label %17

15:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.8, ptr noundef @.str.1, i32 noundef 137, ptr noundef @__PRETTY_FUNCTION__._ZN6Matrix4copyERKS_RS_) #3
  unreachable

16:                                               ; No predecessors!
  br label %17

17:                                               ; preds = %16, %14
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = call noundef i32 @_ZNK6Matrix7getRowsEv(ptr noundef nonnull align 8 dereferenceable(32) %18)
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = call noundef i32 @_ZNK6Matrix7getRowsEv(ptr noundef nonnull align 8 dereferenceable(32) %20)
  %22 = icmp eq i32 %19, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %17
  br label %26

24:                                               ; preds = %17
  call void @__assert_fail(ptr noundef @.str.9, ptr noundef @.str.1, i32 noundef 138, ptr noundef @__PRETTY_FUNCTION__._ZN6Matrix4copyERKS_RS_) #3
  unreachable

25:                                               ; No predecessors!
  br label %26

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

27:                                               ; preds = %53, %26
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = call noundef i32 @_ZNK6Matrix7getRowsEv(ptr noundef nonnull align 8 dereferenceable(32) %29)
  %31 = icmp slt i32 %28, %30
  br i1 %31, label %33, label %32

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

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

34:                                               ; preds = %49, %33
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = call noundef i32 @_ZNK6Matrix7getRowsEv(ptr noundef nonnull align 8 dereferenceable(32) %36)
  %38 = icmp slt i32 %35, %37
  br i1 %38, label %40, label %39

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

40:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = call noundef double @_ZNK6Matrix3getEii(ptr noundef nonnull align 8 dereferenceable(32) %41, i32 noundef %42, i32 noundef %43)
  store double %44, ptr %8, align 8, !tbaa !11
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = load double, ptr %8, align 8, !tbaa !11
  call void @_ZN6Matrix3setEiid(ptr noundef nonnull align 8 dereferenceable(32) %45, i32 noundef %46, i32 noundef %47, double noundef %48)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %49

49:                                               ; preds = %40
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %7, align 4, !tbaa !9
  br label %34, !llvm.loop !13

52:                                               ; preds = %39
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %5, align 4, !tbaa !9
  br label %27, !llvm.loop !15

56:                                               ; preds = %32
  ret void
}

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


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

@.str.1 = external hidden unnamed_addr constant [85 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [43 x i8], align 1
@__PRETTY_FUNCTION__._ZN6Matrix4copyERKS_RS_ = external hidden unnamed_addr constant [51 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [37 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6Matrix7getRowsEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6Matrix10getColumnsEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6Matrix4copyERKS_RS_(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1) local_unnamed_addr #1 align 2 {
  %3 = tail call noundef i32 @_ZNK6Matrix10getColumnsEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %4 = tail call noundef i32 @_ZNK6Matrix10getColumnsEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  %5 = icmp eq i32 %3, %4
  br i1 %5, label %7, label %6

6:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.1, i32 noundef 137, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6Matrix4copyERKS_RS_) #2
  unreachable

7:                                                ; preds = %2
  %8 = tail call noundef i32 @_ZNK6Matrix7getRowsEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %9 = tail call noundef i32 @_ZNK6Matrix7getRowsEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  %10 = icmp eq i32 %8, %9
  br i1 %10, label %.preheader17, label %13

.preheader17:                                     ; preds = %7
  %11 = tail call noundef i32 @_ZNK6Matrix7getRowsEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.preheader, label %._crit_edge20

13:                                               ; preds = %7
  tail call void @__assert_fail(ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.1, i32 noundef 138, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6Matrix4copyERKS_RS_) #2
  unreachable

.preheader:                                       ; preds = %.preheader17, %._crit_edge
  %.019 = phi i32 [ %16, %._crit_edge ], [ 0, %.preheader17 ]
  %14 = tail call noundef i32 @_ZNK6Matrix7getRowsEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

._crit_edge20:                                    ; preds = %._crit_edge, %.preheader17
  ret void

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %16 = add nuw nsw i32 %.019, 1
  %17 = tail call noundef i32 @_ZNK6Matrix7getRowsEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %.preheader, label %._crit_edge20, !llvm.loop !5

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.01618 = phi i32 [ %20, %.lr.ph ], [ 0, %.preheader ]
  %19 = tail call noundef double @_ZNK6Matrix3getEii(ptr noundef nonnull align 8 dereferenceable(32) %0, i32 noundef %.019, i32 noundef %.01618)
  tail call void @_ZN6Matrix3setEiid(ptr noundef nonnull align 8 dereferenceable(32) %1, i32 noundef %.019, i32 noundef %.01618, double noundef %19)
  %20 = add nuw nsw i32 %.01618, 1
  %21 = tail call noundef i32 @_ZNK6Matrix7getRowsEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !7
}

attributes #0 = { noreturn nounwind "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 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 = { noreturn 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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