; LLVM IR from Slingshot-Physics/slingshot-community :: common/math/src/heap_matrix.ll (ZNK10HeapMatrixmiERKS_)

; 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.HeapMatrix = type { i32, i32, i32, i32, i32, [12 x i8], ptr, [8 x i8] }

@.str.1 = external hidden unnamed_addr constant [103 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [27 x i8], align 1
@__PRETTY_FUNCTION__._ZNK10HeapMatrixmiERKS_ = external hidden unnamed_addr constant [59 x i8], align 1

; 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 noundef nonnull align 4 dereferenceable(4) ptr @_ZN10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40), i32 noundef, i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZNK10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40), i32 noundef, i32 noundef) #1 align 2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK10HeapMatrixmiERKS_(ptr dead_on_unwind noalias writable sret(%class.HeapMatrix) align 16 %0, ptr noundef nonnull align 16 dereferenceable(40) %1, ptr noundef nonnull align 16 dereferenceable(40) %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 i1, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = 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
  %13 = load ptr, ptr %5, align 8
  %14 = getelementptr inbounds %class.HeapMatrix, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %class.HeapMatrix, ptr %16, i32 0, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = icmp eq i32 %15, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %3
  br label %23

21:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.10, ptr noundef @.str.1, i32 noundef 240, ptr noundef @__PRETTY_FUNCTION__._ZNK10HeapMatrixmiERKS_) #3
  unreachable

22:                                               ; No predecessors!
  br label %23

23:                                               ; preds = %22, %20
  %24 = getelementptr inbounds %class.HeapMatrix, ptr %13, i32 0, i32 0
  %25 = load i32, ptr %24, align 16, !tbaa !12
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %class.HeapMatrix, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 16, !tbaa !12
  %29 = icmp eq i32 %25, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %23
  br label %33

31:                                               ; preds = %23
  call void @__assert_fail(ptr noundef @.str.9, ptr noundef @.str.1, i32 noundef 241, ptr noundef @__PRETTY_FUNCTION__._ZNK10HeapMatrixmiERKS_) #3
  unreachable

32:                                               ; No predecessors!
  br label %33

33:                                               ; preds = %32, %30
  store i1 false, ptr %7, align 1
  %34 = getelementptr inbounds %class.HeapMatrix, ptr %13, i32 0, i32 0
  %35 = load i32, ptr %34, align 16, !tbaa !12
  %36 = getelementptr inbounds %class.HeapMatrix, ptr %13, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !9
  call void @_ZN10HeapMatrixC1Ejj(ptr noundef nonnull align 16 dereferenceable(40) %0, i32 noundef %35, i32 noundef %37)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !13
  br label %38

38:                                               ; preds = %74, %33
  %39 = load i32, ptr %8, align 4, !tbaa !13
  %40 = getelementptr inbounds %class.HeapMatrix, ptr %13, i32 0, i32 0
  %41 = load i32, ptr %40, align 16, !tbaa !12
  %42 = icmp ult i32 %39, %41
  br i1 %42, label %44, label %43

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

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

45:                                               ; preds = %66, %44
  %46 = load i32, ptr %10, align 4, !tbaa !13
  %47 = getelementptr inbounds %class.HeapMatrix, ptr %13, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = icmp ult i32 %46, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %45
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %73

51:                                               ; preds = %45
  %52 = load i32, ptr %8, align 4, !tbaa !13
  %53 = load i32, ptr %10, align 4, !tbaa !13
  %54 = invoke noundef float @_ZNK10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40) %13, i32 noundef %52, i32 noundef %53)
          to label %55 unwind label %69

55:                                               ; preds = %51
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load i32, ptr %8, align 4, !tbaa !13
  %58 = load i32, ptr %10, align 4, !tbaa !13
  %59 = invoke noundef float @_ZNK10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40) %56, i32 noundef %57, i32 noundef %58)
          to label %60 unwind label %69

60:                                               ; preds = %55
  %61 = fsub float %54, %59
  %62 = load i32, ptr %8, align 4, !tbaa !13
  %63 = load i32, ptr %10, align 4, !tbaa !13
  %64 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40) %0, i32 noundef %62, i32 noundef %63)
          to label %65 unwind label %69

65:                                               ; preds = %60
  store float %61, ptr %64, align 4, !tbaa !14
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %10, align 4, !tbaa !13
  %68 = add i32 %67, 1
  store i32 %68, ptr %10, align 4, !tbaa !13
  br label %45, !llvm.loop !16

69:                                               ; preds = %60, %55, %51
  %70 = landingpad { ptr, i32 }
          cleanup
  %71 = extractvalue { ptr, i32 } %70, 0
  store ptr %71, ptr %11, align 8
  %72 = extractvalue { ptr, i32 } %70, 1
  store i32 %72, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @_ZN10HeapMatrixD1Ev(ptr noundef nonnull align 16 dereferenceable(40) %0) #4
  br label %81

73:                                               ; preds = %50
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %8, align 4, !tbaa !13
  %76 = add i32 %75, 1
  store i32 %76, ptr %8, align 4, !tbaa !13
  br label %38, !llvm.loop !18

77:                                               ; preds = %43
  store i1 true, ptr %7, align 1
  store i32 1, ptr %9, align 4
  %78 = load i1, ptr %7, align 1
  br i1 %78, label %80, label %79

79:                                               ; preds = %77
  call void @_ZN10HeapMatrixD1Ev(ptr noundef nonnull align 16 dereferenceable(40) %0) #4
  br label %80

80:                                               ; preds = %79, %77
  ret void

81:                                               ; preds = %69
  %82 = load ptr, ptr %11, align 8
  %83 = load i32, ptr %12, align 4
  %84 = insertvalue { ptr, i32 } poison, ptr %82, 0
  %85 = insertvalue { ptr, i32 } %84, i32 %83, 1
  resume { ptr, i32 } %85
}

declare void @_ZN10HeapMatrixC1Ejj(ptr, i32, i32)

declare void @_ZN10HeapMatrixD1Ev(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 = { noreturn 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 = { noreturn nounwind }
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 4}
!10 = !{!"_ZTS10HeapMatrix", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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.HeapMatrix = type { i32, i32, i32, i32, i32, [12 x i8], ptr, [8 x i8] }

@.str.1 = external hidden unnamed_addr constant [103 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [27 x i8], align 1
@__PRETTY_FUNCTION__._ZNK10HeapMatrixmiERKS_ = external hidden unnamed_addr constant [59 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40), i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZNK10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40), i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

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

9:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.1, i32 noundef 240, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK10HeapMatrixmiERKS_) #2
  unreachable

10:                                               ; preds = %3
  %11 = load i32, ptr %1, align 16, !tbaa !11
  %12 = load i32, ptr %2, align 16, !tbaa !11
  %13 = icmp eq i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  tail call void @__assert_fail(ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.1, i32 noundef 241, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK10HeapMatrixmiERKS_) #2
  unreachable

15:                                               ; preds = %10
  tail call void @_ZN10HeapMatrixC1Ejj(ptr noundef nonnull align 16 dereferenceable(40) %0, i32 noundef %11, i32 noundef %5)
  %16 = load i32, ptr %1, align 16, !tbaa !11
  %.not = icmp eq i32 %16, 0
  %17 = load i32, ptr %4, align 4
  %.not22 = icmp eq i32 %17, 0
  %or.cond = select i1 %.not, i1 true, i1 %.not22
  br i1 %or.cond, label %._crit_edge21, label %.preheader

.preheader:                                       ; preds = %15, %._crit_edge
  %18 = phi i32 [ %20, %._crit_edge ], [ %16, %15 ]
  %19 = phi i32 [ %21, %._crit_edge ], [ 1, %15 ]
  %.020 = phi i32 [ %22, %._crit_edge ], [ 0, %15 ]
  %.not23 = icmp eq i32 %19, 0
  br i1 %.not23, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %29
  %.pre = load i32, ptr %1, align 16, !tbaa !11
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %20 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %18, %.preheader ]
  %21 = phi i32 [ %32, %._crit_edge.loopexit ], [ 0, %.preheader ]
  %22 = add nuw i32 %.020, 1
  %23 = icmp ult i32 %22, %20
  br i1 %23, label %.preheader, label %._crit_edge21, !llvm.loop !12

.lr.ph:                                           ; preds = %.preheader, %29
  %.01619 = phi i32 [ %31, %29 ], [ 0, %.preheader ]
  %24 = invoke noundef float @_ZNK10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40) %1, i32 noundef %.020, i32 noundef %.01619)
          to label %25 unwind label %34

25:                                               ; preds = %.lr.ph
  %26 = invoke noundef float @_ZNK10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40) %2, i32 noundef %.020, i32 noundef %.01619)
          to label %27 unwind label %34

27:                                               ; preds = %25
  %28 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40) %0, i32 noundef %.020, i32 noundef %.01619)
          to label %29 unwind label %34

29:                                               ; preds = %27
  %30 = fsub float %24, %26
  store float %30, ptr %28, align 4, !tbaa !15
  %31 = add nuw i32 %.01619, 1
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = icmp ult i32 %31, %32
  br i1 %33, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !17

34:                                               ; preds = %27, %25, %.lr.ph
  %35 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN10HeapMatrixD1Ev(ptr noundef nonnull align 16 dereferenceable(40) %0) #3
  resume { ptr, i32 } %35

._crit_edge21:                                    ; preds = %._crit_edge, %15
  ret void
}

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

declare void @_ZN10HeapMatrixD1Ev(ptr) local_unnamed_addr

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 = { noreturn 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 #2 = { noreturn nounwind }
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 4}
!6 = !{!"_ZTS10HeapMatrix", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 32}
!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 0}
!12 = distinct !{!12, !13, !14}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!"llvm.loop.unswitch.partial.disable"}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !8, i64 0}
!17 = distinct !{!17, !13}


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