; LLVM IR from sbischoff-ai/simple-molecular-dynamics :: SimpleMolecularDynamics/SimpleMolecularDynamics/mat.ll (ZN3matC2ERKS_)

; 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.mat = type { ptr, i32, i32 }
%class.vec = type <{ ptr, i32, [4 x i8] }>

; 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 speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #1

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

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

declare void @_ZN3vecC1Ev(ptr noundef nonnull align 8 dereferenceable(12)) unnamed_addr #3

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN3vecD1Ev(ptr noundef nonnull align 8 dereferenceable(12)) unnamed_addr #4

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

declare noundef nonnull align 8 dereferenceable(12) ptr @_ZN3vecaSERKS_(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef nonnull align 8 dereferenceable(12)) #3

; 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
define dso_local void @_ZN3matC2ERKS_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) unnamed_addr #6 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %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
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %class.mat, ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds %class.mat, ptr %8, i32 0, i32 1
  store i32 %11, ptr %12, align 8, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %class.mat, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %16 = getelementptr inbounds %class.mat, ptr %8, i32 0, i32 2
  store i32 %15, ptr %16, align 4, !tbaa !12
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %class.mat, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %20, i64 16)
  %22 = extractvalue { i64, i1 } %21, 1
  %23 = extractvalue { i64, i1 } %21, 0
  %24 = call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %23, i64 8)
  %25 = extractvalue { i64, i1 } %24, 1
  %26 = or i1 %22, %25
  %27 = extractvalue { i64, i1 } %24, 0
  %28 = select i1 %26, i64 -1, i64 %27
  %29 = call noalias noundef nonnull ptr @_Znam(i64 noundef %28) #8
  store i64 %20, ptr %29, align 16
  %30 = getelementptr inbounds i8, ptr %29, i64 8
  %31 = icmp eq i64 %20, 0
  br i1 %31, label %39, label %32

32:                                               ; preds = %2
  %33 = getelementptr inbounds %class.vec, ptr %30, i64 %20
  br label %34

34:                                               ; preds = %36, %32
  %35 = phi ptr [ %30, %32 ], [ %37, %36 ]
  invoke void @_ZN3vecC1Ev(ptr noundef nonnull align 8 dereferenceable(12) %35)
          to label %36 unwind label %62

36:                                               ; preds = %34
  %37 = getelementptr inbounds %class.vec, ptr %35, i64 1
  %38 = icmp eq ptr %37, %33
  br i1 %38, label %39, label %34

39:                                               ; preds = %36, %2
  %40 = getelementptr inbounds %class.mat, ptr %8, i32 0, i32 0
  store ptr %30, ptr %40, align 8, !tbaa !13
  store i32 0, ptr %5, align 4, !tbaa !14
  br label %41

41:                                               ; preds = %59, %39
  %42 = load i32, ptr %5, align 4, !tbaa !14
  %43 = getelementptr inbounds %class.mat, ptr %8, i32 0, i32 1
  %44 = load i32, ptr %43, align 8, !tbaa !9
  %45 = icmp slt i32 %42, %44
  br i1 %45, label %46, label %72

46:                                               ; preds = %41
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %class.mat, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  %50 = load i32, ptr %5, align 4, !tbaa !14
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds %class.vec, ptr %49, i64 %51
  %53 = getelementptr inbounds %class.mat, ptr %8, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !13
  %55 = load i32, ptr %5, align 4, !tbaa !14
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds %class.vec, ptr %54, i64 %56
  %58 = call noundef nonnull align 8 dereferenceable(12) ptr @_ZN3vecaSERKS_(ptr noundef nonnull align 8 dereferenceable(12) %57, ptr noundef nonnull align 8 dereferenceable(12) %52)
  br label %59

59:                                               ; preds = %46
  %60 = load i32, ptr %5, align 4, !tbaa !14
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %5, align 4, !tbaa !14
  br label %41, !llvm.loop !15

62:                                               ; preds = %34
  %63 = landingpad { ptr, i32 }
          cleanup
  %64 = extractvalue { ptr, i32 } %63, 0
  store ptr %64, ptr %6, align 8
  %65 = extractvalue { ptr, i32 } %63, 1
  store i32 %65, ptr %7, align 4
  %66 = icmp eq ptr %30, %35
  br i1 %66, label %71, label %67

67:                                               ; preds = %67, %62
  %68 = phi ptr [ %35, %62 ], [ %69, %67 ]
  %69 = getelementptr inbounds %class.vec, ptr %68, i64 -1
  call void @_ZN3vecD1Ev(ptr noundef nonnull align 8 dereferenceable(12) %69) #7
  %70 = icmp eq ptr %69, %30
  br i1 %70, label %71, label %67

71:                                               ; preds = %67, %62
  call void @_ZdaPvm(ptr noundef %29, i64 noundef %28) #9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  br label %73

72:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  ret void

73:                                               ; preds = %71
  %74 = load ptr, ptr %6, align 8
  %75 = load i32, ptr %7, 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 willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { "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 "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 = { 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 #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 = { nounwind }
attributes #8 = { builtin allocsize(0) }
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 8}
!10 = !{!"_ZTS3mat", !6, i64 0, !11, i64 8, !11, i64 12}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 12}
!13 = !{!10, !6, i64 0}
!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"

%class.vec = type <{ ptr, i32, [4 x i8] }>

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

declare void @_ZN3vecC1Ev(ptr noundef nonnull align 8 dereferenceable(12)) unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

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

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

declare noundef nonnull align 8 dereferenceable(12) ptr @_ZN3vecaSERKS_(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef nonnull align 8 dereferenceable(12)) local_unnamed_addr #1

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

.loopexit19.thread:                               ; preds = %2
  store ptr %.ptr14, ptr %0, align 8, !tbaa !9
  br label %._crit_edge

14:                                               ; preds = %2
  %15 = getelementptr inbounds %class.vec, ptr %.ptr14, i64 %7
  br label %16

16:                                               ; preds = %17, %14
  %.idx = phi i64 [ 8, %14 ], [ %.add, %17 ]
  %.ptr.ptr = getelementptr inbounds i8, ptr %12, i64 %.idx
  invoke void @_ZN3vecC1Ev(ptr noundef nonnull align 8 dereferenceable(12) %.ptr.ptr)
          to label %17 unwind label %28

17:                                               ; preds = %16
  %.add = add nuw nsw i64 %.idx, 16
  %.ptr13 = getelementptr inbounds i8, ptr %12, i64 %.add
  %18 = icmp eq ptr %.ptr13, %15
  br i1 %18, label %.loopexit19, label %16

.loopexit19:                                      ; preds = %17
  %.pre = load i32, ptr %4, align 8, !tbaa !12
  %19 = icmp sgt i32 %.pre, 0
  store ptr %.ptr14, ptr %0, align 8, !tbaa !9
  br i1 %19, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.loopexit19, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.loopexit19 ]
  %20 = load ptr, ptr %1, align 8, !tbaa !9
  %21 = getelementptr inbounds %class.vec, ptr %20, i64 %indvars.iv
  %22 = load ptr, ptr %0, align 8, !tbaa !9
  %23 = getelementptr inbounds %class.vec, ptr %22, i64 %indvars.iv
  %24 = tail call noundef nonnull align 8 dereferenceable(12) ptr @_ZN3vecaSERKS_(ptr noundef nonnull align 8 dereferenceable(12) %23, ptr noundef nonnull align 8 dereferenceable(12) %21)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = load i32, ptr %4, align 8, !tbaa !12
  %26 = sext i32 %25 to i64
  %27 = icmp slt i64 %indvars.iv.next, %26
  br i1 %27, label %.lr.ph, label %._crit_edge, !llvm.loop !13

28:                                               ; preds = %16
  %29 = landingpad { ptr, i32 }
          cleanup
  %30 = icmp eq i64 %.idx, 8
  br i1 %30, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %28, %.preheader
  %.idx15 = phi i64 [ %.add16, %.preheader ], [ %.idx, %28 ]
  %.add16 = add nsw i64 %.idx15, -16
  %.ptr18 = getelementptr inbounds i8, ptr %12, i64 %.add16
  tail call void @_ZN3vecD1Ev(ptr noundef nonnull align 8 dereferenceable(12) %.ptr18) #6
  %31 = icmp eq i64 %.add16, 8
  br i1 %31, label %.loopexit, label %.preheader

.loopexit:                                        ; preds = %.preheader, %28
  tail call void @_ZdaPvm(ptr noundef nonnull %12, i64 noundef %11) #7
  resume { ptr, i32 } %29

._crit_edge:                                      ; preds = %.lr.ph, %.loopexit19.thread, %.loopexit19
  ret void
}

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 0}
!10 = !{!"_ZTS3mat", !11, i64 0, !6, i64 8, !6, i64 12}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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