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

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

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

29:                                               ; preds = %3
  %30 = getelementptr inbounds %class.vec, ptr %27, i64 %17
  br label %31

31:                                               ; preds = %33, %29
  %32 = phi ptr [ %27, %29 ], [ %34, %33 ]
  invoke void @_ZN3vecC1Ev(ptr noundef nonnull align 8 dereferenceable(12) %32)
          to label %33 unwind label %54

33:                                               ; preds = %31
  %34 = getelementptr inbounds %class.vec, ptr %32, i64 1
  %35 = icmp eq ptr %34, %30
  br i1 %35, label %36, label %31

36:                                               ; preds = %33, %3
  %37 = getelementptr inbounds %class.mat, ptr %11, i32 0, i32 0
  store ptr %27, ptr %37, align 8, !tbaa !14
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %51, %36
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %42, label %68

42:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #7
  %43 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN3vecC1EPdi(ptr noundef nonnull align 8 dereferenceable(12) %10, ptr noundef null, i32 noundef %43)
  %44 = getelementptr inbounds %class.mat, ptr %11, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds %class.vec, ptr %45, i64 %47
  %49 = invoke noundef nonnull align 8 dereferenceable(12) ptr @_ZN3vecaSERKS_(ptr noundef nonnull align 8 dereferenceable(12) %48, ptr noundef nonnull align 8 dereferenceable(12) %10)
          to label %50 unwind label %64

50:                                               ; preds = %42
  call void @_ZN3vecD1Ev(ptr noundef nonnull align 8 dereferenceable(12) %10) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #7
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %7, align 4, !tbaa !9
  br label %38, !llvm.loop !15

54:                                               ; preds = %31
  %55 = landingpad { ptr, i32 }
          cleanup
  %56 = extractvalue { ptr, i32 } %55, 0
  store ptr %56, ptr %8, align 8
  %57 = extractvalue { ptr, i32 } %55, 1
  store i32 %57, ptr %9, align 4
  %58 = icmp eq ptr %27, %32
  br i1 %58, label %63, label %59

59:                                               ; preds = %59, %54
  %60 = phi ptr [ %32, %54 ], [ %61, %59 ]
  %61 = getelementptr inbounds %class.vec, ptr %60, i64 -1
  call void @_ZN3vecD1Ev(ptr noundef nonnull align 8 dereferenceable(12) %61) #7
  %62 = icmp eq ptr %61, %27
  br i1 %62, label %63, label %59

63:                                               ; preds = %59, %54
  call void @_ZdaPvm(ptr noundef %26, i64 noundef %25) #9
  br label %69

64:                                               ; preds = %42
  %65 = landingpad { ptr, i32 }
          cleanup
  %66 = extractvalue { ptr, i32 } %65, 0
  store ptr %66, ptr %8, align 8
  %67 = extractvalue { ptr, i32 } %65, 1
  store i32 %67, ptr %9, align 4
  call void @_ZN3vecD1Ev(ptr noundef nonnull align 8 dereferenceable(12) %10) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #7
  br label %69

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

69:                                               ; preds = %64, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  br label %70

70:                                               ; preds = %69
  %71 = load ptr, ptr %8, align 8
  %72 = load i32, ptr %9, align 4
  %73 = insertvalue { ptr, i32 } poison, ptr %71, 0
  %74 = insertvalue { ptr, i32 } %73, i32 %72, 1
  resume { ptr, i32 } %74
}

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

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

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

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

declare i32 @__gxx_personality_v0(...)

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

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

declare void @_ZN3vecC1EPdi(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef, i32 noundef) unnamed_addr #4

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #4 = { "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 = { 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 = { 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 #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTS3mat", !6, i64 0, !10, i64 8, !10, i64 12}
!13 = !{!12, !10, i64 12}
!14 = !{!12, !6, 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: mustprogress uwtable
define dso_local void @_ZN3matC2Eii(ptr nocapture noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca %class.vec, align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %1, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %2, ptr %6, align 4, !tbaa !11
  %7 = sext i32 %1 to i64
  %8 = icmp slt i32 %1, 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) #6
  store i64 %7, ptr %12, align 16
  %.ptr16 = getelementptr inbounds i8, ptr %12, i64 8
  %13 = icmp eq i32 %1, 0
  br i1 %13, label %.loopexit22.thread, label %14

.loopexit22.thread:                               ; preds = %3
  store ptr %.ptr16, ptr %0, align 8, !tbaa !12
  br label %._crit_edge

14:                                               ; preds = %3
  %15 = getelementptr inbounds %class.vec, ptr %.ptr16, 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 %24

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

.loopexit22:                                      ; preds = %17
  store ptr %.ptr16, ptr %0, align 8, !tbaa !12
  %19 = icmp sgt i32 %1, 0
  br i1 %19, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.loopexit22
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %23
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %23 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #7
  call void @_ZN3vecC1EPdi(ptr noundef nonnull align 8 dereferenceable(12) %4, ptr noundef null, i32 noundef %2)
  %20 = load ptr, ptr %0, align 8, !tbaa !12
  %21 = getelementptr inbounds %class.vec, ptr %20, i64 %indvars.iv
  %22 = invoke noundef nonnull align 8 dereferenceable(12) ptr @_ZN3vecaSERKS_(ptr noundef nonnull align 8 dereferenceable(12) %21, ptr noundef nonnull align 8 dereferenceable(12) %4)
          to label %23 unwind label %28

23:                                               ; preds = %.lr.ph
  call void @_ZN3vecD1Ev(ptr noundef nonnull align 8 dereferenceable(12) %4) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #7
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

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

.preheader:                                       ; preds = %24, %.preheader
  %.idx17 = phi i64 [ %.add18, %.preheader ], [ %.idx, %24 ]
  %.add18 = add nsw i64 %.idx17, -16
  %.ptr20 = getelementptr inbounds i8, ptr %12, i64 %.add18
  tail call void @_ZN3vecD1Ev(ptr noundef nonnull align 8 dereferenceable(12) %.ptr20) #7
  %27 = icmp eq i64 %.add18, 8
  br i1 %27, label %.loopexit, label %.preheader

.loopexit:                                        ; preds = %.preheader, %24
  tail call void @_ZdaPvm(ptr noundef nonnull %12, i64 noundef %11) #8
  br label %30

28:                                               ; preds = %.lr.ph
  %29 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN3vecD1Ev(ptr noundef nonnull align 8 dereferenceable(12) %4) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #7
  br label %30

._crit_edge:                                      ; preds = %23, %.loopexit22.thread, %.loopexit22
  ret void

30:                                               ; preds = %28, %.loopexit
  %.pn = phi { ptr, i32 } [ %29, %28 ], [ %25, %.loopexit ]
  resume { ptr, i32 } %.pn
}

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #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) local_unnamed_addr #5

declare void @_ZN3vecC1EPdi(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef, i32 noundef) 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 #3

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { builtin allocsize(0) }
attributes #7 = { nounwind }
attributes #8 = { 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, !10, i64 8}
!6 = !{!"_ZTS3mat", !7, i64 0, !10, i64 8, !10, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 12}
!12 = !{!6, !7, i64 0}
!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,SROAPass,SimplifyCFGPass,TailCallElimPass