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

; 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 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [103 x i8], align 1
@__PRETTY_FUNCTION__._ZNK10HeapMatrix3rowEj = external hidden unnamed_addr constant [47 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

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

16:                                               ; preds = %3
  br label %19

17:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 196, ptr noundef @__PRETTY_FUNCTION__._ZNK10HeapMatrix3rowEj) #3
  unreachable

18:                                               ; No predecessors!
  br label %19

19:                                               ; preds = %18, %16
  store i1 false, ptr %7, align 1
  %20 = getelementptr inbounds %class.HeapMatrix, ptr %11, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !13
  call void @_ZN10HeapMatrixC1Ejj(ptr noundef nonnull align 16 dereferenceable(40) %0, i32 noundef 1, i32 noundef %21)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %36, %19
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = getelementptr inbounds %class.HeapMatrix, ptr %11, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !13
  %26 = icmp ult i32 %23, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %43

28:                                               ; preds = %22
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = invoke noundef float @_ZNK10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40) %11, i32 noundef %29, i32 noundef %30)
          to label %32 unwind label %39

32:                                               ; preds = %28
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40) %0, i32 noundef 0, i32 noundef %33)
          to label %35 unwind label %39

35:                                               ; preds = %32
  store float %31, ptr %34, align 4, !tbaa !14
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = add i32 %37, 1
  store i32 %38, ptr %8, align 4, !tbaa !9
  br label %22, !llvm.loop !16

39:                                               ; preds = %32, %28
  %40 = landingpad { ptr, i32 }
          cleanup
  %41 = extractvalue { ptr, i32 } %40, 0
  store ptr %41, ptr %9, align 8
  %42 = extractvalue { ptr, i32 } %40, 1
  store i32 %42, ptr %10, align 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 %47

43:                                               ; preds = %27
  store i1 true, ptr %7, align 1
  %44 = load i1, ptr %7, align 1
  br i1 %44, label %46, label %45

45:                                               ; preds = %43
  call void @_ZN10HeapMatrixD1Ev(ptr noundef nonnull align 16 dereferenceable(40) %0) #4
  br label %46

46:                                               ; preds = %45, %43
  ret void

47:                                               ; preds = %39
  %48 = load ptr, ptr %9, align 8
  %49 = load i32, ptr %10, align 4
  %50 = insertvalue { ptr, i32 } poison, ptr %48, 0
  %51 = insertvalue { ptr, i32 } %50, i32 %49, 1
  resume { ptr, i32 } %51
}

declare i32 @__gxx_personality_v0(...)

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS10HeapMatrix", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !6, i64 32}
!13 = !{!12, !10, i64 4}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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.HeapMatrix = type { i32, i32, i32, i32, i32, [12 x i8], ptr, [8 x i8] }

@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [103 x i8], align 1
@__PRETTY_FUNCTION__._ZNK10HeapMatrix3rowEj = external hidden unnamed_addr constant [47 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

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

6:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 196, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK10HeapMatrix3rowEj) #2
  unreachable

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %1, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !11
  tail call void @_ZN10HeapMatrixC1Ejj(ptr noundef nonnull align 16 dereferenceable(40) %0, i32 noundef 1, i32 noundef %9)
  %10 = load i32, ptr %8, align 4, !tbaa !11
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %7, %14
  %.010 = phi i32 [ %15, %14 ], [ 0, %7 ]
  %11 = invoke noundef float @_ZNK10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40) %1, i32 noundef %2, i32 noundef %.010)
          to label %12 unwind label %18

12:                                               ; preds = %.lr.ph
  %13 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40) %0, i32 noundef 0, i32 noundef %.010)
          to label %14 unwind label %18

14:                                               ; preds = %12
  store float %11, ptr %13, align 4, !tbaa !12
  %15 = add nuw i32 %.010, 1
  %16 = load i32, ptr %8, align 4, !tbaa !11
  %17 = icmp ult i32 %15, %16
  br i1 %17, label %.lr.ph, label %._crit_edge, !llvm.loop !14

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

._crit_edge:                                      ; preds = %14, %7
  ret void
}

declare i32 @__gxx_personality_v0(...)

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 0}
!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 4}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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