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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.uadd.with.overflow.i64(i64, i64) #0

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #1

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPvm(ptr noundef, i64 noundef) #4

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN7d2MatMNaSERKS_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) #6 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.d2MatMN, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.d2MatMN, ptr %8, i32 0, i32 0
  store i32 %11, ptr %12, align 8, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.d2MatMN, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %16 = getelementptr inbounds %struct.d2MatMN, ptr %8, i32 0, i32 1
  store i32 %15, ptr %16, align 4, !tbaa !12
  %17 = getelementptr inbounds %struct.d2MatMN, ptr %8, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %19, i64 16)
  %21 = extractvalue { i64, i1 } %20, 1
  %22 = extractvalue { i64, i1 } %20, 0
  %23 = call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %22, i64 8)
  %24 = extractvalue { i64, i1 } %23, 1
  %25 = or i1 %21, %24
  %26 = extractvalue { i64, i1 } %23, 0
  %27 = select i1 %25, i64 -1, i64 %26
  %28 = call noalias noundef nonnull ptr @_Znam(i64 noundef %27) #7
  store i64 %19, ptr %28, align 16
  %29 = getelementptr inbounds i8, ptr %28, i64 8
  %30 = icmp eq i64 %19, 0
  br i1 %30, label %38, label %31

31:                                               ; preds = %2
  %32 = getelementptr inbounds %struct.d2VecN, ptr %29, i64 %19
  br label %33

33:                                               ; preds = %35, %31
  %34 = phi ptr [ %29, %31 ], [ %36, %35 ]
  invoke void @_ZN6d2VecNC1Ev(ptr noundef nonnull align 8 dereferenceable(16) %34)
          to label %35 unwind label %46

35:                                               ; preds = %33
  %36 = getelementptr inbounds %struct.d2VecN, ptr %34, i64 1
  %37 = icmp eq ptr %36, %32
  br i1 %37, label %38, label %33

38:                                               ; preds = %35, %2
  %39 = getelementptr inbounds %struct.d2MatMN, ptr %8, i32 0, i32 2
  store ptr %29, ptr %39, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #8
  store i32 0, ptr %7, align 4, !tbaa !14
  br label %40

40:                                               ; preds = %69, %38
  %41 = load i32, ptr %7, align 4, !tbaa !14
  %42 = getelementptr inbounds %struct.d2MatMN, ptr %8, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !9
  %44 = icmp slt i32 %41, %43
  br i1 %44, label %56, label %45

45:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #8
  br label %72

46:                                               ; preds = %33
  %47 = landingpad { ptr, i32 }
          cleanup
  %48 = extractvalue { ptr, i32 } %47, 0
  store ptr %48, ptr %5, align 8
  %49 = extractvalue { ptr, i32 } %47, 1
  store i32 %49, ptr %6, align 4
  %50 = icmp eq ptr %29, %34
  br i1 %50, label %55, label %51

51:                                               ; preds = %51, %46
  %52 = phi ptr [ %34, %46 ], [ %53, %51 ]
  %53 = getelementptr inbounds %struct.d2VecN, ptr %52, i64 -1
  call void @_ZN6d2VecND1Ev(ptr noundef nonnull align 8 dereferenceable(16) %53) #8
  %54 = icmp eq ptr %53, %29
  br i1 %54, label %55, label %51

55:                                               ; preds = %51, %46
  call void @_ZdaPvm(ptr noundef %28, i64 noundef %27) #9
  br label %73

56:                                               ; preds = %40
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.d2MatMN, ptr %57, i32 0, i32 2
  %59 = load ptr, ptr %58, align 8, !tbaa !13
  %60 = load i32, ptr %7, align 4, !tbaa !14
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds %struct.d2VecN, ptr %59, i64 %61
  %63 = getelementptr inbounds %struct.d2MatMN, ptr %8, i32 0, i32 2
  %64 = load ptr, ptr %63, align 8, !tbaa !13
  %65 = load i32, ptr %7, align 4, !tbaa !14
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds %struct.d2VecN, ptr %64, i64 %66
  %68 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN6d2VecNaSERKS_(ptr noundef nonnull align 8 dereferenceable(16) %67, ptr noundef nonnull align 8 dereferenceable(16) %62)
  br label %69

69:                                               ; preds = %56
  %70 = load i32, ptr %7, align 4, !tbaa !14
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %7, align 4, !tbaa !14
  br label %40, !llvm.loop !15

72:                                               ; preds = %45
  ret ptr %8

73:                                               ; preds = %55
  %74 = load ptr, ptr %5, align 8
  %75 = load i32, ptr %6, align 4
  %76 = insertvalue { ptr, i32 } poison, ptr %74, 0
  %77 = insertvalue { ptr, i32 } %76, i32 %75, 1
  resume { ptr, i32 } %77
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nobuiltin allocsize(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 "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 = { nobuiltin 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 #5 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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 #7 = { builtin allocsize(0) }
attributes #8 = { nounwind }
attributes #9 = { builtin 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 = !{!10, !6, i64 8}
!14 = !{!11, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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 }

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #0

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPvm(ptr noundef, i64 noundef) local_unnamed_addr #3

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

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN7d2MatMNaSERKS_(ptr noundef nonnull returned align 8 dereferenceable(16) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %1) local_unnamed_addr #4 align 2 personality ptr @__gxx_personality_v0 {
  %3 = load <2 x i32>, ptr %1, align 8, !tbaa !5
  store <2 x i32> %3, ptr %0, align 8, !tbaa !5
  %4 = extractelement <2 x i32> %3, i64 0
  %5 = sext i32 %4 to i64
  %6 = icmp slt i32 %4, 0
  %7 = shl nsw i64 %5, 4
  %8 = or disjoint i64 %7, 8
  %9 = select i1 %6, i64 -1, i64 %8
  %10 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %9) #5
  store i64 %5, ptr %10, align 16
  %.ptr13 = getelementptr inbounds i8, ptr %10, i64 8
  %11 = icmp eq i32 %4, 0
  br i1 %11, label %.loopexit18.thread, label %13

.loopexit18.thread:                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %.ptr13, ptr %12, align 8, !tbaa !9
  br label %._crit_edge

13:                                               ; preds = %2
  %14 = getelementptr inbounds %struct.d2VecN, ptr %.ptr13, i64 %5
  br label %15

15:                                               ; preds = %16, %13
  %.idx = phi i64 [ 8, %13 ], [ %.add, %16 ]
  %.ptr.ptr = getelementptr inbounds i8, ptr %10, i64 %.idx
  invoke void @_ZN6d2VecNC1Ev(ptr noundef nonnull align 8 dereferenceable(16) %.ptr.ptr)
          to label %16 unwind label %21

16:                                               ; preds = %15
  %.add = add nuw nsw i64 %.idx, 16
  %.ptr12 = getelementptr inbounds i8, ptr %10, i64 %.add
  %17 = icmp eq ptr %.ptr12, %14
  br i1 %17, label %.loopexit18, label %15

.loopexit18:                                      ; preds = %16
  %.pre = load i32, ptr %0, align 8, !tbaa !12
  %18 = icmp sgt i32 %.pre, 0
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %.ptr13, ptr %19, align 8, !tbaa !9
  br i1 %18, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.loopexit18
  %20 = getelementptr inbounds i8, ptr %1, i64 8
  br label %25

._crit_edge:                                      ; preds = %25, %.loopexit18.thread, %.loopexit18
  ret ptr %0

21:                                               ; preds = %15
  %22 = landingpad { ptr, i32 }
          cleanup
  %23 = icmp eq i64 %.idx, 8
  br i1 %23, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %21, %.preheader
  %.idx14 = phi i64 [ %.add15, %.preheader ], [ %.idx, %21 ]
  %.add15 = add nsw i64 %.idx14, -16
  %.ptr17 = getelementptr inbounds i8, ptr %10, i64 %.add15
  tail call void @_ZN6d2VecND1Ev(ptr noundef nonnull align 8 dereferenceable(16) %.ptr17) #6
  %24 = icmp eq i64 %.add15, 8
  br i1 %24, label %.loopexit, label %.preheader

.loopexit:                                        ; preds = %.preheader, %21
  tail call void @_ZdaPvm(ptr noundef nonnull %10, i64 noundef %9) #7
  resume { ptr, i32 } %22

25:                                               ; preds = %.lr.ph, %25
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %25 ]
  %26 = load ptr, ptr %20, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.d2VecN, ptr %26, i64 %indvars.iv
  %28 = load ptr, ptr %19, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.d2VecN, ptr %28, i64 %indvars.iv
  %30 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZN6d2VecNaSERKS_(ptr noundef nonnull align 8 dereferenceable(16) %29, ptr noundef nonnull align 8 dereferenceable(16) %27)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = load i32, ptr %0, align 8, !tbaa !12
  %32 = sext i32 %31 to i64
  %33 = icmp slt i64 %indvars.iv.next, %32
  br i1 %33, label %25, label %._crit_edge, !llvm.loop !13
}

attributes #0 = { nobuiltin allocsize(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 = { "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 "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 = { nobuiltin 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 #4 = { 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 #5 = { builtin allocsize(0) }
attributes #6 = { nounwind }
attributes #7 = { builtin 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"_ZTS7d2MatMN", !6, i64 0, !6, i64 4, !11, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass