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

; 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.d2VecN = type { i32, ptr }
%struct.d2MatMN = type { i32, i32, ptr }

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN6d2VecND1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #0

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

declare void @_ZN6d2VecNC1Ei(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) unnamed_addr #2

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

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

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

18:                                               ; preds = %3
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN6d2VecNC1ERKS_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %19)
  br label %52

20:                                               ; preds = %3
  store i1 false, ptr %7, align 1
  %21 = getelementptr inbounds %struct.d2MatMN, ptr %11, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !14
  call void @_ZN6d2VecNC1Ei(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %22)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !15
  br label %23

23:                                               ; preds = %41, %20
  %24 = load i32, ptr %8, align 4, !tbaa !15
  %25 = getelementptr inbounds %struct.d2MatMN, ptr %11, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !14
  %27 = icmp slt i32 %24, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %48

29:                                               ; preds = %23
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.d2MatMN, ptr %11, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = load i32, ptr %8, align 4, !tbaa !15
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds %struct.d2VecN, ptr %32, i64 %34
  %36 = invoke noundef float @_ZNK6d2VecN3DotERKS_(ptr noundef nonnull align 8 dereferenceable(16) %30, ptr noundef nonnull align 8 dereferenceable(16) %35)
          to label %37 unwind label %44

37:                                               ; preds = %29
  %38 = load i32, ptr %8, align 4, !tbaa !15
  %39 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %38)
          to label %40 unwind label %44

40:                                               ; preds = %37
  store float %36, ptr %39, align 4, !tbaa !17
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %8, align 4, !tbaa !15
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %8, align 4, !tbaa !15
  br label %23, !llvm.loop !19

44:                                               ; preds = %37, %29
  %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
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @_ZN6d2VecND1Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #4
  br label %53

48:                                               ; preds = %28
  store i1 true, ptr %7, align 1
  %49 = load i1, ptr %7, align 1
  br i1 %49, label %51, label %50

50:                                               ; preds = %48
  call void @_ZN6d2VecND1Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #4
  br label %51

51:                                               ; preds = %50, %48
  br label %52

52:                                               ; preds = %51, %18
  ret void

53:                                               ; preds = %44
  %54 = load ptr, ptr %9, align 8
  %55 = load i32, ptr %10, align 4
  %56 = insertvalue { ptr, i32 } poison, ptr %54, 0
  %57 = insertvalue { ptr, i32 } %56, i32 %55, 1
  resume { ptr, i32 } %57
}

declare void @_ZN6d2VecNC1ERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2

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

attributes #0 = { 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 = { "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 = { 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 #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, !11, i64 0}
!10 = !{!"_ZTS6d2VecN", !11, i64 0, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 4}
!13 = !{!"_ZTS7d2MatMN", !11, i64 0, !11, i64 4, !6, i64 8}
!14 = !{!13, !11, i64 0}
!15 = !{!11, !11, i64 0}
!16 = !{!13, !6, i64 8}
!17 = !{!18, !18, i64 0}
!18 = !{!"float", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; 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.d2VecN = type { i32, ptr }

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN6d2VecND1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #0

declare void @_ZN6d2VecNC1Ei(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) unnamed_addr #1

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

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

7:                                                ; preds = %3
  tail call void @_ZN6d2VecNC1ERKS_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %2)
  br label %.loopexit

8:                                                ; preds = %3
  %9 = load i32, ptr %1, align 8, !tbaa !13
  tail call void @_ZN6d2VecNC1Ei(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %9)
  %10 = load i32, ptr %1, align 8, !tbaa !13
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %8
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  br label %13

13:                                               ; preds = %.lr.ph, %20
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %20 ]
  %14 = load ptr, ptr %12, align 8, !tbaa !14
  %15 = getelementptr inbounds %struct.d2VecN, ptr %14, i64 %indvars.iv
  %16 = invoke noundef float @_ZNK6d2VecN3DotERKS_(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 8 dereferenceable(16) %15)
          to label %17 unwind label %24

17:                                               ; preds = %13
  %18 = trunc nuw nsw i64 %indvars.iv to i32
  %19 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %18)
          to label %20 unwind label %24

20:                                               ; preds = %17
  store float %16, ptr %19, align 4, !tbaa !15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = load i32, ptr %1, align 8, !tbaa !13
  %22 = sext i32 %21 to i64
  %23 = icmp slt i64 %indvars.iv.next, %22
  br i1 %23, label %13, label %.loopexit, !llvm.loop !17

24:                                               ; preds = %17, %13
  %25 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN6d2VecND1Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #3
  resume { ptr, i32 } %25

.loopexit:                                        ; preds = %20, %8, %7
  ret void
}

declare void @_ZN6d2VecNC1ERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1

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

attributes #0 = { 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 = { "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 = { 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, !7, i64 0}
!6 = !{!"_ZTS6d2VecN", !7, i64 0, !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 = !{!12, !7, i64 4}
!12 = !{!"_ZTS7d2MatMN", !7, i64 0, !7, i64 4, !10, i64 8}
!13 = !{!12, !7, i64 0}
!14 = !{!12, !10, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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