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

; 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__._ZN10HeapMatrixpLERKS_ = external hidden unnamed_addr constant [55 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 noundef nonnull align 16 dereferenceable(40) ptr @_ZN10HeapMatrixpLERKS_(ptr noundef nonnull align 16 dereferenceable(40) %0, ptr noundef nonnull align 16 dereferenceable(40) %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %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 = getelementptr inbounds %class.HeapMatrix, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 16, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %class.HeapMatrix, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 16, !tbaa !9
  %14 = icmp eq i32 %10, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  br label %18

16:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.9, ptr noundef @.str.1, i32 noundef 290, ptr noundef @__PRETTY_FUNCTION__._ZN10HeapMatrixpLERKS_) #3
  unreachable

17:                                               ; No predecessors!
  br label %18

18:                                               ; preds = %17, %15
  %19 = getelementptr inbounds %class.HeapMatrix, ptr %8, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !12
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %class.HeapMatrix, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !12
  %24 = icmp eq i32 %20, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %18
  br label %28

26:                                               ; preds = %18
  call void @__assert_fail(ptr noundef @.str.10, ptr noundef @.str.1, i32 noundef 291, ptr noundef @__PRETTY_FUNCTION__._ZN10HeapMatrixpLERKS_) #3
  unreachable

27:                                               ; No predecessors!
  br label %28

28:                                               ; preds = %27, %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !13
  br label %29

29:                                               ; preds = %56, %28
  %30 = load i32, ptr %5, align 4, !tbaa !13
  %31 = getelementptr inbounds %class.HeapMatrix, ptr %8, i32 0, i32 0
  %32 = load i32, ptr %31, align 16, !tbaa !9
  %33 = icmp ult i32 %30, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %29
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %59

35:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !13
  br label %36

36:                                               ; preds = %52, %35
  %37 = load i32, ptr %7, align 4, !tbaa !13
  %38 = getelementptr inbounds %class.HeapMatrix, ptr %8, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !12
  %40 = icmp ult i32 %37, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %36
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %55

42:                                               ; preds = %36
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load i32, ptr %5, align 4, !tbaa !13
  %45 = load i32, ptr %7, align 4, !tbaa !13
  %46 = call noundef float @_ZNK10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40) %43, i32 noundef %44, i32 noundef %45)
  %47 = load i32, ptr %5, align 4, !tbaa !13
  %48 = load i32, ptr %7, align 4, !tbaa !13
  %49 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40) %8, i32 noundef %47, i32 noundef %48)
  %50 = load float, ptr %49, align 4, !tbaa !14
  %51 = fadd float %50, %46
  store float %51, ptr %49, align 4, !tbaa !14
  br label %52

52:                                               ; preds = %42
  %53 = load i32, ptr %7, align 4, !tbaa !13
  %54 = add i32 %53, 1
  store i32 %54, ptr %7, align 4, !tbaa !13
  br label %36, !llvm.loop !16

55:                                               ; preds = %41
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %5, align 4, !tbaa !13
  %58 = add i32 %57, 1
  store i32 %58, ptr %5, align 4, !tbaa !13
  br label %29, !llvm.loop !18

59:                                               ; preds = %34
  ret ptr %8
}

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 0}
!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 4}
!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"

@.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__._ZN10HeapMatrixpLERKS_ = external hidden unnamed_addr constant [55 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 noundef nonnull align 16 dereferenceable(40) ptr @_ZN10HeapMatrixpLERKS_(ptr noundef nonnull returned align 16 dereferenceable(40) %0, ptr noundef nonnull align 16 dereferenceable(40) %1) local_unnamed_addr #0 align 2 {
  %3 = load i32, ptr %0, align 16, !tbaa !5
  %4 = load i32, ptr %1, align 16, !tbaa !5
  %5 = icmp eq i32 %3, %4
  br i1 %5, label %7, label %6

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

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %1, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !11
  %12 = icmp eq i32 %9, %11
  br i1 %12, label %.preheader12, label %13

.preheader12:                                     ; preds = %7
  %.not = icmp eq i32 %3, 0
  %.not16 = icmp eq i32 %9, 0
  %or.cond = or i1 %.not, %.not16
  br i1 %or.cond, label %._crit_edge15, label %.preheader

13:                                               ; preds = %7
  tail call void @__assert_fail(ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.1, i32 noundef 291, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN10HeapMatrixpLERKS_) #2
  unreachable

.preheader:                                       ; preds = %.preheader12, %._crit_edge
  %14 = phi i32 [ %16, %._crit_edge ], [ %3, %.preheader12 ]
  %15 = phi i32 [ %17, %._crit_edge ], [ 1, %.preheader12 ]
  %.01114 = phi i32 [ %18, %._crit_edge ], [ 0, %.preheader12 ]
  %.not17 = icmp eq i32 %15, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph

._crit_edge15:                                    ; preds = %._crit_edge, %.preheader12
  ret ptr %0

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %0, align 16, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %16 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %14, %.preheader ]
  %17 = phi i32 [ %25, %._crit_edge.loopexit ], [ 0, %.preheader ]
  %18 = add nuw i32 %.01114, 1
  %19 = icmp ult i32 %18, %16
  br i1 %19, label %.preheader, label %._crit_edge15, !llvm.loop !12

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.013 = phi i32 [ %24, %.lr.ph ], [ 0, %.preheader ]
  %20 = tail call noundef float @_ZNK10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40) %1, i32 noundef %.01114, i32 noundef %.013)
  %21 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40) %0, i32 noundef %.01114, i32 noundef %.013)
  %22 = load float, ptr %21, align 4, !tbaa !15
  %23 = fadd float %20, %22
  store float %23, ptr %21, align 4, !tbaa !15
  %24 = add nuw i32 %.013, 1
  %25 = load i32, ptr %8, align 4, !tbaa !11
  %26 = icmp ult i32 %24, %25
  br i1 %26, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !17
}

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 }

!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 = 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,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass