; LLVM IR from SOHNE/Dura2D :: src/math/d2MatMN.ll (ZNK7d2MatMNmlERKS_)

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

%struct.d2MatMN = type { i32, i32, ptr }
%struct.d2VecN = type { i32, ptr }

declare i32 @__gxx_personality_v0(...)

; 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 uwtable
declare dso_local void @_ZNK7d2MatMN9TransposeEv(ptr dead_on_unwind noalias writable sret(%struct.d2MatMN) align 8, ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

declare noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #2

declare noundef float @_ZNK6d2VecN3DotERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK7d2MatMNmlERKS_(ptr dead_on_unwind noalias writable sret(%struct.d2MatMN) align 8 %0, ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(16) %2) #1 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.d2MatMN, align 8
  %8 = alloca i1, align 1
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %4, align 8
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %5, align 8
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.d2MatMN, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.d2MatMN, ptr %14, i32 0, i32 1
  %19 = load i32, ptr %18, align 4, !tbaa !12
  %20 = icmp ne i32 %17, %19
  br i1 %20, label %21, label %30

21:                                               ; preds = %3
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.d2MatMN, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !12
  %25 = getelementptr inbounds %struct.d2MatMN, ptr %14, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !9
  %27 = icmp ne i32 %24, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %21
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN7d2MatMNC1ERKS_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %29)
  br label %93

30:                                               ; preds = %21, %3
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZNK7d2MatMN9TransposeEv(ptr dead_on_unwind writable sret(%struct.d2MatMN) align 8 %7, ptr noundef nonnull align 8 dereferenceable(16) %31)
  store i1 false, ptr %8, align 1
  %32 = getelementptr inbounds %struct.d2MatMN, ptr %14, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !9
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.d2MatMN, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !12
  invoke void @_ZN7d2MatMNC1Eii(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %33, i32 noundef %36)
          to label %37 unwind label %44

37:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !13
  br label %38

38:                                               ; preds = %85, %37
  %39 = load i32, ptr %11, align 4, !tbaa !13
  %40 = getelementptr inbounds %struct.d2MatMN, ptr %14, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !9
  %42 = icmp slt i32 %39, %41
  br i1 %42, label %48, label %43

43:                                               ; preds = %38
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %88

44:                                               ; preds = %30
  %45 = landingpad { ptr, i32 }
          cleanup
  %46 = extractvalue { ptr, i32 } %45, 0
  store ptr %46, ptr %9, align 8
  %47 = extractvalue { ptr, i32 } %45, 1
  store i32 %47, ptr %10, align 4
  br label %92

48:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !13
  br label %49

49:                                               ; preds = %77, %48
  %50 = load i32, ptr %13, align 4, !tbaa !13
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.d2MatMN, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !12
  %54 = icmp slt i32 %50, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %49
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %84

56:                                               ; preds = %49
  %57 = getelementptr inbounds %struct.d2MatMN, ptr %14, i32 0, i32 2
  %58 = load ptr, ptr %57, align 8, !tbaa !14
  %59 = load i32, ptr %11, align 4, !tbaa !13
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds %struct.d2VecN, ptr %58, i64 %60
  %62 = getelementptr inbounds %struct.d2MatMN, ptr %7, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !14
  %64 = load i32, ptr %13, align 4, !tbaa !13
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds %struct.d2VecN, ptr %63, i64 %65
  %67 = invoke noundef float @_ZNK6d2VecN3DotERKS_(ptr noundef nonnull align 8 dereferenceable(16) %61, ptr noundef nonnull align 8 dereferenceable(16) %66)
          to label %68 unwind label %80

68:                                               ; preds = %56
  %69 = getelementptr inbounds %struct.d2MatMN, ptr %0, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !14
  %71 = load i32, ptr %11, align 4, !tbaa !13
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds %struct.d2VecN, ptr %70, i64 %72
  %74 = load i32, ptr %13, align 4, !tbaa !13
  %75 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16) %73, i32 noundef %74)
          to label %76 unwind label %80

76:                                               ; preds = %68
  store float %67, ptr %75, align 4, !tbaa !15
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %13, align 4, !tbaa !13
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %13, align 4, !tbaa !13
  br label %49, !llvm.loop !17

80:                                               ; preds = %68, %56
  %81 = landingpad { ptr, i32 }
          cleanup
  %82 = extractvalue { ptr, i32 } %81, 0
  store ptr %82, ptr %9, align 8
  %83 = extractvalue { ptr, i32 } %81, 1
  store i32 %83, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @_ZN7d2MatMND1Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #3
  br label %92

84:                                               ; preds = %55
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %11, align 4, !tbaa !13
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %11, align 4, !tbaa !13
  br label %38, !llvm.loop !19

88:                                               ; preds = %43
  store i1 true, ptr %8, align 1
  store i32 1, ptr %12, align 4
  %89 = load i1, ptr %8, align 1
  br i1 %89, label %91, label %90

90:                                               ; preds = %88
  call void @_ZN7d2MatMND1Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #3
  br label %91

91:                                               ; preds = %90, %88
  call void @_ZN7d2MatMND1Ev(ptr noundef nonnull align 8 dereferenceable(16) %7) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  br label %93

92:                                               ; preds = %80, %44
  call void @_ZN7d2MatMND1Ev(ptr noundef nonnull align 8 dereferenceable(16) %7) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  br label %94

93:                                               ; preds = %91, %28
  ret void

94:                                               ; preds = %92
  %95 = load ptr, ptr %9, align 8
  %96 = load i32, ptr %10, align 4
  %97 = insertvalue { ptr, i32 } poison, ptr %95, 0
  %98 = insertvalue { ptr, i32 } %97, i32 %96, 1
  resume { ptr, i32 } %98
}

declare void @_ZN7d2MatMNC1Eii(ptr, i32, i32)

declare void @_ZN7d2MatMNC1ERKS_(ptr, ptr)

declare void @_ZN7d2MatMND1Ev(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 = { "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, !11, i64 0}
!10 = !{!"_ZTS7d2MatMN", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 8}
!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"

%struct.d2MatMN = type { i32, i32, ptr }
%struct.d2VecN = type { i32, ptr }

declare i32 @__gxx_personality_v0(...)

; 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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK7d2MatMN9TransposeEv(ptr dead_on_unwind noalias writable sret(%struct.d2MatMN) align 8, ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

declare noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #2

declare noundef float @_ZNK6d2VecN3DotERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK7d2MatMNmlERKS_(ptr dead_on_unwind noalias writable sret(%struct.d2MatMN) align 8 %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(16) %2) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca %struct.d2MatMN, align 8
  %5 = load i32, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %.not = icmp eq i32 %5, %7
  br i1 %.not, label %13, label %8

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %2, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = load i32, ptr %1, align 8, !tbaa !5
  %.not20 = icmp eq i32 %10, %11
  br i1 %.not20, label %13, label %12

12:                                               ; preds = %8
  tail call void @_ZN7d2MatMNC1ERKS_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %2)
  br label %50

13:                                               ; preds = %8, %3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  call void @_ZNK7d2MatMN9TransposeEv(ptr dead_on_unwind nonnull writable sret(%struct.d2MatMN) align 8 %4, ptr noundef nonnull align 8 dereferenceable(16) %2)
  %14 = load i32, ptr %1, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %2, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !11
  invoke void @_ZN7d2MatMNC1Eii(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %14, i32 noundef %16)
          to label %.preheader22 unwind label %27

.preheader22:                                     ; preds = %13
  %17 = load i32, ptr %1, align 8, !tbaa !5
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %.preheader.lr.ph, label %._crit_edge25

.preheader.lr.ph:                                 ; preds = %.preheader22
  %19 = getelementptr inbounds i8, ptr %1, i64 8
  %20 = getelementptr inbounds i8, ptr %4, i64 8
  %21 = getelementptr inbounds i8, ptr %0, i64 8
  %22 = load i32, ptr %15, align 4, !tbaa !11
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %.preheader, label %._crit_edge25

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %24 = phi i32 [ %29, %._crit_edge ], [ %17, %.preheader.lr.ph ]
  %25 = phi i32 [ %30, %._crit_edge ], [ %22, %.preheader.lr.ph ]
  %indvars.iv28 = phi i64 [ %indvars.iv.next29, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %.lr.ph, label %._crit_edge

27:                                               ; preds = %13
  %28 = landingpad { ptr, i32 }
          cleanup
  br label %49

._crit_edge.loopexit:                             ; preds = %43
  %.pre = load i32, ptr %1, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %29 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %24, %.preheader ]
  %30 = phi i32 [ %44, %._crit_edge.loopexit ], [ %25, %.preheader ]
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %31 = sext i32 %29 to i64
  %32 = icmp slt i64 %indvars.iv.next29, %31
  br i1 %32, label %.preheader, label %._crit_edge25, !llvm.loop !12

.lr.ph:                                           ; preds = %.preheader, %43
  %indvars.iv = phi i64 [ %indvars.iv.next, %43 ], [ 0, %.preheader ]
  %33 = load ptr, ptr %19, align 8, !tbaa !15
  %34 = getelementptr inbounds %struct.d2VecN, ptr %33, i64 %indvars.iv28
  %35 = load ptr, ptr %20, align 8, !tbaa !15
  %36 = getelementptr inbounds %struct.d2VecN, ptr %35, i64 %indvars.iv
  %37 = invoke noundef float @_ZNK6d2VecN3DotERKS_(ptr noundef nonnull align 8 dereferenceable(16) %34, ptr noundef nonnull align 8 dereferenceable(16) %36)
          to label %38 unwind label %47

38:                                               ; preds = %.lr.ph
  %39 = load ptr, ptr %21, align 8, !tbaa !15
  %40 = getelementptr inbounds %struct.d2VecN, ptr %39, i64 %indvars.iv28
  %41 = trunc nuw nsw i64 %indvars.iv to i32
  %42 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16) %40, i32 noundef %41)
          to label %43 unwind label %47

43:                                               ; preds = %38
  store float %37, ptr %42, align 4, !tbaa !16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %44 = load i32, ptr %15, align 4, !tbaa !11
  %45 = sext i32 %44 to i64
  %46 = icmp slt i64 %indvars.iv.next, %45
  br i1 %46, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !18

47:                                               ; preds = %38, %.lr.ph
  %48 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN7d2MatMND1Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #3
  br label %49

._crit_edge25:                                    ; preds = %._crit_edge, %.preheader.lr.ph, %.preheader22
  call void @_ZN7d2MatMND1Ev(ptr noundef nonnull align 8 dereferenceable(16) %4) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  br label %50

49:                                               ; preds = %47, %27
  %.pn = phi { ptr, i32 } [ %48, %47 ], [ %28, %27 ]
  call void @_ZN7d2MatMND1Ev(ptr noundef nonnull align 8 dereferenceable(16) %4) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  resume { ptr, i32 } %.pn

50:                                               ; preds = %._crit_edge25, %12
  ret void
}

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

declare void @_ZN7d2MatMNC1ERKS_(ptr, ptr) local_unnamed_addr

declare void @_ZN7d2MatMND1Ev(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 = { "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 = !{!"_ZTS7d2MatMN", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = distinct !{!12, !13, !14}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!"llvm.loop.unswitch.partial.disable"}
!15 = !{!6, !10, i64 8}
!16 = !{!17, !17, i64 0}
!17 = !{!"float", !8, i64 0}
!18 = distinct !{!18, !13}


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